arrays

Mutable list or array structure in Bash? How can I easily append to it?

I'm trying to collect string values in a bash script. What's the simplest way that I can append string values to a list or array structure such that I can echo them out at the end? ...

Ruby on Rails: Aggregating several columns into an Array

I'm developing a Ruby on Rails app where one of my database tables has 10 columns (pile_1 through to pile_10). It would be convenient to access these columns in the model as a 10-element Array. It feels like I should be able to coerce composed_of into doing what I want, but I can't figure out how. Can anyone enlighten me, or suggest a b...

In Perl, why do I need to @b = @{dclone(\@a)}? Why can't I just @b = dclone(\@a)?

I have an array of various things including scalars and arrays. I want to make a copy of it, and tried the following: @b = dclone(\@a) but then when I try to read one of the scalar values from b, I get nothing back. Everything appears to work when I copy it this way, though: @b = @{dclone(\@a)} What is the reason? ...

How can I make if statement using the number of array in PHP?

findParent() function find array. There could be one array or more than one. Now I want to make if statement depends on the number of array. How can I make if statement using the number of array? function findParent($order_id){ ... $Q = $this->db->get('omc_order_item'); if ($Q->num_rows() > 0){ foreach ($Q->re...

How to get data in an array with PHP?

findParent() function returns the following array. Array ( [0] => Array ( [order_item_id] => 3 [order_id] => 2 [product_id] => 77 [quantity] => 1 [price] => 268.00 ) ) I want to get 2 in [order_id]. I tried the following but it does not work. $child...

Passing an array into hidden_field ROR

I'm trying to pass an array into a hidden_field. The following User has 3 roles [2,4,5] >> u = User.find_by_login("lesa") => #<User id: 5, login: "lesa", email: "[email protected]", crypted_password: "0f2776e68f1054a2678ad69a3b28e35ad9f42078", salt: "f02ef9e00d16f1b9f82dfcc488fdf96bf5aab4a8", created_at: "2009-12-29 15:15:51", upd...

Arrays with different datatypes i.e. strings and integers. (Objectorientend)

For example I've 3 books: Booknumber (int), Booktitle (string), Booklanguage (string), Bookprice (int). now I want to have an array called books[3][4]. I'm gettin the data I set via setBooknumber like this: Book1.getBooknumber(), Book1.getBooktitle(),...,Book3.getBookprice(). Now how do I realize this books[3][4] array. I can't call ...

Trying to join a two-dimensional array in Javascript

I'm trying to convert a two-dimensional array to a string in order to store it in the localStorage array. However, there is something wrong with this code I cannot identify: for(x in array) { if(array[x] instanceof Array) { array[x] = array[x].join("`"); } } var string = array.join("@"); localStorage[key] = string; Doe...

A Better Way To Build a Packet - Byte by Byte?

This is related to my question asked here today on SO. Is there a better way to build a packet to send over serial rather than doing this: unsigned char buff[255]; buff[0] = 0x02 buff[1] = 0x01 buff[2] = 0x03 WriteFile(.., buff,3, &dwBytesWrite,..); Note: I have about twenty commands to send, so if there was a better way to send the...

A Many-Many Association Hidden_Field edit problem. ROR

I'm trying to pass an array into a hidden_field. The following User has 3 roles [2,4,5] >> u = User.find_by_login("lesa") => #<User id: 5, login: "lesa", email: "[email protected]", crypted_password: "0f2776e68f1054a2678ad69a3b28e35ad9f42078", salt: "f02ef9e00d16f1b9f82dfcc488fdf96bf5aab4a8", created_at: "2009-12-29 15:15:51", upd...

Dictionary<int [], bool> - compare values in the array, not reference?

Hi, I am using dictionary for storing ID,otherID and bool value. Unfortunately it compares array reference, therefore I cannot use it. Is there any way how to have an array as key but compare its values instead of reference? Thanks ...

Create array using loop for related items

I'm trying to create "related articles" for our news, based on tags (single word tags). If a story is tagged with 3 tags, I'd like to be able to pull up the most recent entries for each tag, order them by date, and display only the most recent 5. Here's what I'm trying, that obviously doesn't work, because it overwrites the array varia...

Access random item in list.

Hi All, I have an ArrayList, and I need to be able to click a button and then randomly pick out a string from that list and display it in a messagebox. How would I go about doing this? Any help at all is greatly appreciated. Thank you Bael ...

ASP .NET C# - Use an array to populate a listbox?

The website I am working on will contain a drop-down list that shows a number of reason codes. Is it possible to populate a drop-down list with an array derived from a custom class? Something like this: ASPX Page <asp:DropDownList ID="ddlReasonsWhy" runat="server"></asp:DropDownList> ASPX Code Behind protected void Page_Load(objec...

Multi-dimensional filter to eliminate "bad" items from a large table?

I have a large table of N items with M (M>=3) distinct properties per item, From this table I have to remove all items for which the same table contains an item that scores equal or better on all properties. I have an algorithm (python) that solves it already, but it is output-sensitive and has a worst case of approx. O((n²+n)/2) when n...

Issue with char[] in VS2008 - why does strcat append to the end of an empty array?

I am passing an empty char array that I need to recursively fill using strcat(). However, in the VS debugger, the array is not empty, it's full of some weird junk characters that I don't recognise. strcat() then appends to the end of these junk characters rather than at the front of the array. I have also tried encoded[0] = '\0' to clea...

Issue with char array of size one and strcat

Ok, I'm really confused by this behaviour in VS2008. This code.. char data[512] = ""; char c[1] = ""; c[0] = '1'; strcat(data, c); .. results in data being set to this string value: 1ÌÌÌÌhÿ Surely it should just be 1? How can I ensure data only contains the single char[] that I copy into it (i.e. 1)? Why does strcat() copy all t...

can i use stdClass like an array?

is it possible to make stdClass objects work like a generically indexed array? i.e. $array = Array ( [0] => 120 [1] => 382 [2] => 552 [3] => 595 [4] => 616 ) would be constructed like $a = array(); $array[] = 120; $array[] = 382; etc. but if i do that with an object it just overwrites itself: $obj = new stdClass; $obj->a = 120; $...

How to prevent double round trip with Linq and ToArray() Method

I am trying to use an Array instead of a list in my query. But I must get the count first before I can iterate through the objects returned from the database. Here is my code: var FavArray = favorites.OrderByDescending(y => y.post_date).Skip((page - 1) * config.MaxRowsPerPage).Take(config.MaxRowsPerPage).ToArray(); int F...

How can I read from a Perl filehandle that is an array element?

I quickly jotted off a Perl script that would average a few files with just columns of numbers. It involves reading from an array of filehandles. Here is the script: #!/usr/local/bin/perl use strict; use warnings; use Symbol; die "Usage: $0 file1 [file2 ...]\n" unless scalar(@ARGV); my @fhs; foreach(@ARGV){ my $fh = gensym; ...