For starters, you should get in the habit of adding 'use warnings' and 'use
strict' to the beginning of your scripts.

Secondly, it looks like you are trying to use $jon as a reference to @jon,
but you never assign it that value.  You should probably change

   @address = qw/ $jon $marsha $ben $abe /;

to

   @address = (\@jon,\@marsha,\@ben,\@abe);

Thirdly, I would get rid of the C-style for statement and just do a Perl
foreach()

   foreach $item(@address){
     print $item->[0];
     #access the first element of the array pointed to by $item
     print ${$item}[1];
     #another way to access by dereferencing the array
   }

Finally, you should check out 'perldoc perllol' (List of Lists)

-----Original Message-----
From: Rob Trahan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 18, 2003 8:41 AM
To: [EMAIL PROTECTED]
Subject: Accessing arrays of arrays


Hello,

I was wondering how I would could access arrays of arrays. I would like to
be able to get to (print, for now) the value in each nested array. Here
is what I've been trying:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/perl

@jon = qw/ "jon" "hansfelt" "123-1122" /;
@ben = qw/ "ben" "jones" "222-1231" /;
@marsha = qw/ "marsha" "padgett" "333-9087" /;
@abe = qw/ "abe" "johnson" "421-4623" /;

@address = qw/ $jon $marsha $ben $abe /;
@address = sort @address;

for ($i = 0; $i <= $#address; $i++) {
     @temp = $address[$i];
     #print @temp."\n";
     print $temp[0]."\n";
     print $temp[1]."\n";
 }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I've tried different variations on the above with no success. Should I use
a 2-D array instead?

Thank you,
Robert


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to