I have a perl array of to-do tasks that looks like this:
@todos = (
"1 (A) Complete online final @evm4700 t:2010-06-02",
"3 Write thank-you t:2010-06-10",
"4 (B) Clean t:2010-05-30",
"5 Donate to LSF t:2010-06-02",
"6 (A) t:2010-05-30 Pick up dry cleaning",
"2 (C) Call Chris Johnson t:2010-06-01"
);
That first number is the task's ID. If a task has ([A-Z]) next to, that defines the task's priority. What I want to do is sort the tasks array in a way that places the prioritized items first (and in order):
@todos = (
"1 (A) Complete online final @evm4700 t:2010-06-02",
"6 (A) t:2010-05-30 Pick up dry cleaning",
"4 (B) Clean t:2010-05-30",
"2 (C) Call Chris Johnson t:2010-06-01"
"3 Write thank-you t:2010-06-10",
"5 Donate to LSF t:2010-06-02",
);
I cannot use a regular sort() because of those IDs next to the tasks, so I'm assuming that some sort of customized sorting subroutine is needed. However, my knowledge of how to do this efficiently in perl is minimal.
Thanks, all.
Below is the beginning of a chunk of SPIM code:
.data
a: .space 20
b: .space 20
.text
set_all:
sw $ra,0($sp)
li $t0,0
li $t1,10
............
Unfortunately, the second array I declare ('b') causes the SPIM interpreter to spit out:
spim: (parser) syntax error on line 3
of file spim.out b: .space 20
^
Similar code works when I only have one array -- it seems to be the second that screws it up. I've prodded at it but can't figure out what it is about that statement that makes it break. Any thoughts? Thanks for any insight.
I'm new to C#, so this may be a basic question. What I need to do is put an array such as the one below in a class library and then make a call to it. So I'd want the aproprate picture to appear via the class and this array. I know there's a much simpler way to make certain pictures appear, but this is a requirement for the project. It's an asp.NET website in C#.
string[] PictureArray;
PictureArray = new string[3];
PictureArray[0] = "~/pics/grl.jpg";
PictureArray[1] = "~/pics/pop.jpg";
PictureArray[2] = "~/pics/str.jpg";
PictureArray[3] = "~/pics/unk.jpg";
So,
I have some code which looks like this:
byte* ar;
foo(ar) // Allocates a new[] byte array for ar
...
delete[] ar;
To make this safer, I used a scoped_array:
byte* arRaw;
scoped_array ar;
foo(arRaw);
ar.reset(arRaw);
...
// No delete[]
The question is, Is there any existing way to do this using just the scoped_array, without using a temporary raw array?
I can probably write an in-place "resetter" class, just wondering if the functionality exists and I'm missing it.
Thanks,
Dan
Hi,
I have a 2D array, call it 'A'. I have two other 2D arrays, call them 'ix' and 'iy'. I would like to create an output array whose elements are the elements of A at the index pairs provided by x_idx and y_idx. I can do this with a loop as follows:
for i=1:nx
for j=1:ny
output(i,j) = A(ix(i,j),iy(i,j));
end
end
How can I do this without the loop? If I do output = A(ix,iy), I get the value of A over the whole range of (ix)X(iy).
Thank you,
Jason
What's a better way to traverse an array while iterating through another array? For example, if I have two arrays like the following:
names = [ "Rover", "Fido", "Lassie", "Calypso"]
breeds = [ "Terrier", "Lhasa Apso", "Collie", "Bulldog"]
Assuming the arrays correspond with one another - that is, Rover is a Terrier, Fido is a Lhasa Apso, etc. - I'd like to create a dog class, and a new dog object for each item:
class Dog
attr_reader :name, :breed
def initialize(name, breed)
@name = name
@breed = breed
end
end
I can iterate through names and breeds with the following:
index = 0
names.each do |name|
dog = Dog.new("#{name}", "#{breeds[index]}")
index = index.next
end
However, I get the feeling that using the index variable is the wrong way to go about it. What would be a better way?
I am attempting to move data from a recordset directly into an array. I know this is possible, but specifically I want to do this in VBA as this is being done in MS Access 2003.
Typically I would do something like the following to archive this:
Dim vaData As Variant
Dim rst As ADODB.Recordset
' Pull data into recordset code here...
' Populate the array with the whole recordset.
vaData = rst.GetRows
What differences exist between VB and VBA which makes this type of operation not work?
What about performance concerns? Is this an "expensive" operations?
I have a choice.
I have an array of ordered strings that I need to store and access. It looks like I can choose between using:
A TStringList
A Dynamic Array of strings, and
A Linked List of strings
In what circumstances is each of these better than the others?
Which is best for small lists (under 10 items)?
Which is best for large lists (over 1000 items)?
Which is best for huge lists (over 1,000,000 items)?
Which is best tor minimize memory use?
Which is best to minimize loading and/or access time?
For reference, I am using Delphi 2009.
I have an array look like below.
$array[0]['keyword'] = 'cricket ';
$array[0]['noofhits'] = '26';
$array[0]['keyword'] = 'food ';
$array[0]['noofhits'] = '17';
$array[0]['keyword'] = 'mypax';
$array[0]['noofhits'] = '22';
$array[0]['keyword'] = 'next';
$array[0]['noofhits'] = '22';
$array[0]['keyword'] = 'nextbutton';
$array[0]['noofhits'] = '22';
$array[0]['keyword'] = 'picture';
$array[0]['noofhits'] = '18';
I want to sort the array using the noofhits.How can I do?Advance Thanks for your advice.
Hi there, this is my first time posting a question here.
I have an array of 12 buttons on a timeline that when first visiting that part of the timeline, get a CLICK eventlistener added to them using a for loop. All of them work perfectly at that point.
When you click one it plays a frame label inside the specific movieClip and reveals a bio on the corresponding person with a close button and removes the CLICK eventlisteners for each button, again using a for loop. The close button plays a closing animation, and then the timeline goes back to the first frame (the one with the 12 buttons on it) and the CLICK eventlisteners are re-added, but now only the first 9 buttons of the array work. There are no output errors and the code to re-add the eventlisteners is exactly the same as the first time that works. I am completely at a loss and am wondering if anyone else has run into this problem.
All of my buttons are named correctly, there are absolutely no output errors (I've used the debug module) and I made sure the array with the buttons in it is outputting all 12 at the moment the close button is clicked to add the eventlisteners back.
for (var q = 0; q < ackBoDBtnArray.length; q++){
contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[q]].addEventListener(MouseEvent.CLICK, showBio);
}
private function showBio(eo:MouseEvent):void {
trace("show the bio");
bodVar = ackBoDBtnArray.getIndex(eo.target.name);
contentArea_mc.acknowledgements_mc.BoD_mc.gotoAndPlay(ackBoDPgArray[bodVar]);
contentArea_mc.acknowledgements_mc.BoD_mc.closeBio_btn.addEventListener(MouseEvent.CLICK, hideBio);
for (var r = 0; r < ackBoDBtnArray.length; r++){
contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[r]].mouseEnabled = false;
contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[r]].removeEventListener(MouseEvent.CLICK, showBio);
}
}
private function hideBio(eo:MouseEvent):void {
trace("hide it!");
contentArea_mc.acknowledgements_mc.BoD_mc.closeBio_btn.removeEventListener(MouseEvent.CLICK, hideBio);
contentArea_mc.acknowledgements_mc.BoD_mc.gotoAndPlay(ackBoDClosePgArray[bodVar]);
for (var s = 0; s < ackBoDBtnArray.length; s++){
trace(ackBoDBtnArray[s]);
contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[s]].mouseEnabled = true;
contentArea_mc.acknowledgements_mc.BoD_mc[ackBoDBtnArray[s]].addEventListener(MouseEvent.CLICK, showBio);
}
Thanks in advance for any help and insight you can provide...I have a slight feeling that its something that may be obvious to another set of eyes...haha.
I have two functions and one array
function A {
$segments = array();
$segments['word']=$var1;
$segments['word2']=$var2;
$segments['word3']=$var3;
return $segments;
}
function B {
$someVar=$segments['word'];
$someVar1=$segments['word'];
$someVar2=$segments['word'];
$vars['other_stuff']...
return $vars;
}
but I am not passing $segments['word']...word3'] to the second function.
I am passing
$segments[0];
$segments[1];
etc...
How can I pass the keys to second function
$segments['word']
$segments['word1']
$segments['word2']
Thank you,
You will write a program that
evaluates the integral of sin(x) using
the left-hand rectangle rule with 2000
subintervals, over 10 intervals. The
intervals to test are [0, 1), [1, 2),
…, [8, 9), [9, 10). You will declare
an array of type double that can hold
10 elements, and you will use this
array to hold all 10 results you get
from evaluating each interval.
I am in testing my code, what should be the output?
For example, [0, 1)? Any idea?
Thanks.
Hi all ! I use to load plist which are in my main Bundle (Ressource folder) into an array using :
NSString *path = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:nomPlist ];
NSMutableArray *tmpQuestion = [[NSArray alloc] initWithContentsOfFile:path];
arrayQuestion = [ [NSArray alloc] initWithArray:tmpQuestion];
[tmpQuestion release];
since i decide to change the content of my plist and that main bundle is read only how can i make this array loading plist from the Documents directory of my app ? ?
thanks to all
Hi,
I want to send an array of objects in the get request string. I know this isn't the optimal solution, but I really just want to get this up and running.
If I have a class, something like this
public class Data
{
public int a { get; set; }
public int b { get; set; }
}
public class RequestViewData
{
public IList<Data> MyData { get; set; }
}
I thought I could bind the MVC route to a web request like this
http://localhost:8080/Request?MyData[0].a=1&MyData[0].b=2&MyData[1].a=3&[MyData[1].b=4
But all this does is create an array of two data objects without populating the values 1,2, 3 or 4.
Is there a way to bind complex objects arrays?
The following code (copied from a question from about a year ago) works fine under Scala 2.7.7, but does not behave correctly under Scala 2.8.0 (Beta 1, RC8).
import scala.xml
class Person(name : String, age : Int) {
def toXml(): xml.Elem =
<person><name>{ name }</name><age>{ age }</age></person>
}
def peopleToXml(people: Array[Person]): xml.Elem = {
<people>{ for {person <- people} yield person.toXml }</people>
}
val data = Array(new Person("joe",40), new Person("mary", 35))
println(peopleToXml(data))
The output (according to 2.7.7) should be:
<people><person><name>joe</name><age>40</age></person><person><name>mary</name><age>35</age></person></people>
but instead comes out as:
<people>\[Lscala.xml.Elem;@17821782</people>
How do I get this to behave as it did in 2.7.x?
I've retrieved some data from the database, which is in the following structure:
[0]
[item_id] = 197
[dice_chat_css] = "foo"
[dice_image] = "bar.png"
[1]
[item_id] = 128
[dice_chat_css] = "foo"
[dice_image] = "bar.png"
The most convenient and computationally inexpensive way for me to pass this data to the rest of my (PHP) application is with item_id as the index, because it saves having to loop over the array to look up values. If this was a flat array, I could accomplish this trivially with array_flip, but since it isn't, it's my pick of using either the multidimensional array_flip listed in the comments on PHP.net, or roll my own logic:
for ($i = 0; $i < sizeOf($r); $i++){
$s[$r[$i]['item_id']]['dice_image'] = $r[$i]['dice_image'];
$s[$r[$i]['item_id']]['dice_chat_css'] = $r[$i]['dice_chat_css'];
}
I know it's simple, but it feels like I'm reinventing the wheel here. Is there an accepted, more optimized method available or am I being weird about this?
I am trying to seperate values in an array so i can pass them to another function.
Am using the select-Object function within a for loop to go through each line and separate the timestamp and value fields.
However, it doesn't matter what i do the below code only displays the first select-object variable for each line. The second select-object command doesn't seem to work as my output is a blank line for each of the 6 rows.
Any ideas on how to get both values
$ReportData = $SystemStats.get_performance_graph_csv_statistics( (,$Query) )
### Allocate a new encoder and turn the byte array into a string
$ASCII = New-Object -TypeName System.Text.ASCIIEncoding
$csvdata = $ASCII.GetString($ReportData[0].statistic_data)
$csv2 = convertFrom-CSV $csvdata
$newarray = $csv2 | Where-Object {$_.utilization -ne "0.0000000000e+00" -and $_.utilization -ne "nan" }
for ( $n = 0; $n -lt $newarray.Length; $n++)
{
$nTime = $newarray[$n]
$nUtil = $newarray[$n]
$util = $nUtil | select-object Utilization
$util
$tstamp = $nTime | select-object timestamp
$tstamp
}
We are programming a ST269 microcontroller which has two IR distance sensors. To calibrate these sensors we made one table for each sensor with the distance we measured and the corresponding value we get from the ADC.
Now we want to use one function to approximate the values in between. So we defined two two-dimensional arrays (one for each sensor) as global variables. In our function we then want to copy the one array we want to work with to a working array and approximate our values.
So here's the code:
...
unsigned int ir_werte_re[][] = {
{8,553},
...
{83,133}
};
unsigned int ir_werte_li[][] = {
{8,566},
...
{83,147}
};
...
unsigned int geradenaproximation(unsigned int messwert, unsigned int seite)
{
unsigned int working_array[16][16];
unsigned int i = 0;
if (seite == 0) {
for (i = 0; i < sizeof(working_array); i++) {
working_array[i][0] = ir_werte_li[i][0];
i++;
}
}
else {
for (i = 0; i < sizeof(working_array); i++) {
working_array[i][0] = ir_werte_re[i][0];
i++;
}
}
i = 0;
unsigned int y1 = 0;
unsigned int x1 = 0;
...
}
This code is in a file called sensor.c. We didn't write anything about our global arrays in the sensor.h should we? The sensor.h of course is included in our main.c and there the function is called.
We also tried to copy the arrays via
memcpy(working_array, ir_werte_li, sizeof(working_array));
And in every way we do this we get a
syntax error near unsigned
in the line where we're declaring
unsigned int y1 = 0;
and I'm pretty sure that there is no syntax error in this line : )
The last time I spend coding in C is a few years away so I'm not sure if the way we try to do this is good. Perhaps we can solve this by using a pointer instead of really copying the array or something. So please help me out I'll appreciate your bits on this.
Hello. I am creating a site that requires a very small postcode checker. I have approx 8 postcode prefix's, HX, HD, BD, LS etc in an array. I also have a simple input field and submit btn. When the user types in a postcode for example HX5 9DU I want Jquery to check the array, if there is match for the first 2/3 letters I want a div to fade in displaying a message.
How would I do this? Many thanks in advance.
Hi there.. i have problem to get all element in array of object using jquery...
i get this code from internet...
var id = 123;
var test = new Object();
test.Identification = id;
test.Group = "users";
test.Persons = new Array();
test.Persons.push({"FirstName":" AA ","LastName":"LA"});
test.Persons.push({"FirstName":" BB ","LastName":"LBB"});
test.Persons.push({"FirstName":" CC","LastName":"LC"});
test.Persons.push({"FirstName":" DD","LastName":"LD"});
how to get each of "FirstName" and "LastName" in Persons using JQuery??
I have an array created with this code:
var widthRange = new Array();
widthRange[46] = { sel:46, min:0, max:52 };
widthRange[66] = { sel:66, min:52, max:70 };
widthRange[90] = { sel:90, min:70, max:94 };
I want to get each of the values 46, 66, 90 in a loop. I tried for (var key in widthRange) but this gives me a whole bunch of extra properties (I assume they are functions on the object). I can't use a regular for loop since the values are not sequential.