Rob Trahan wrote:
> 
> Hello,

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;

First you have to create an array of arrays (actually an array of array references.)

my @address = ( [ qw/ "jon"    "hansfelt" "123-1122" / ],
                [ qw/ "ben"    "jones"    "222-1231" / ],
                [ qw/ "marsha" "padgett"  "333-9087" / ],
                [ qw/ "abe"    "johnson"  "421-4623" / ],
              );


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

for my $temp ( @address ) {
    #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?

You should probably also read up on Perl's documentation with regard to data
structures and references.

perldoc perldata
perldoc perldsc
perldoc perllol
perldoc perlreftut
perldoc perlref


John
-- 
use Perl;
program
fulfillment

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

Reply via email to