You have to place a REFERENCE to an array into another array:

----------
@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 = ( \@jon, \@ben, \@marsha, \@abe);

-------------

The backslash passes a reference to the arrays into @address

then access them by:
print $$address[0][0];        # prints jon
print $$address[1][2];        # prints 222-1231

The first $ dereferences the contents of $address[0] so that you can get to
the first element.


see perldoc perlref, 'Learning Perl', 'Programming Perl' and the 'Perl
Cookbook' for further instruction.


References are the gateway to the power of perl data structures.  Love them,
live them and learn 'em!




"Rob Trahan" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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]

Reply via email to