CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [orange] firstidx, 'array of arrays': Edit Log


Nov 26, 2012, 11:55 AM

Views: 3162
Re: [orange] firstidx, 'array of arrays'

Strictly speaking, perl does not support multi-dimensional arrays. Proper use of references largely hides this fact.

In your case, the symbol @services refers to a single dimensional array. Each element of that array is a reference. Each reference refers to a list of scalars (one "row" in your notation). The data that you think of as 'column 1" consists of the second (indexes start with zero) element of each of these arrays. To treat that colulmn as a list, you must explicitly extract it.

my @col1 = map ($_->[1]) @services; 
my $index= firstidx { $_ eq '7' } @col1;

Update: Chris Charley neatly combined these two statements into one.
Good Luck,

(This post was edited by BillKSmith on Nov 26, 2012, 9:16 PM)

Edit Log:
Post edited by BillKSmith (Veteran) on Nov 26, 2012, 9:16 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives