Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks
I've written this code and i'm getting an error while executing it.
#! use strict; use warnings; my @arr = (1,2,3,4); my @arr2 = ('a',4,2,'s'); my $rarr = \@arr; my $rarr2 = \@arr2; my @arra = ($rarr,$rarr2); # I am trying to print the array @arr & @arr2. # i also want to access individual elements in those arrays using refe +rences print $arra{$$rarr[0]};
Where am i going wrong?

Replies are listed 'Best First'.
Re: Array of arrays- references
by wfsp (Abbot) on May 27, 2010 at 07:04 UTC
    Nearly. :-)

    Take a look at tye's References quick reference tutorial for help on figuring out all that punctuation.

    #! /usr/bin/perl use strict; use warnings; my @arr = (1,2,3,4); my @arr2 = ('a',4,2,'s'); my $rarr = \@arr; my $rarr2 = \@arr2; my @arra = ($rarr,$rarr2); # I am trying to print the array @arr & @arr2. # i also want to access individual elements in those arrays using refe +rences #print $arra{$$rarr[0]}; print @{$arra[0]}, qq{\n}; print $arra[0]->[0], qq{\n\n}; for my $aref (@arra){ for my $ele (@{$aref}){ print qq{$ele\n}; } print qq{\n}; }
Re: Array of arrays- references
by Khen1950fx (Canon) on May 27, 2010 at 07:58 UTC
    I tried like this:
    #!/usr/bin/perl use strict; use warnings; my @AoA = ( [1, 2, 3, 4], ['a', 4, 2, 's'], ); for my $aref (@AoA) { print "\t[@$aref]\n"; } print "\t$AoA[0][0]\n", "\t$AoA[1][0]\n"; for my $i (0 .. $#AoA) { for my $j (0 .. $#{$AoA[$i]}) { print "\t$AoA[$i][$j]\n"; } }
Re: Array of arrays- references
by Anonymous Monk on May 27, 2010 at 09:34 UTC
    I guess i was looking at a hash of arrays and not array of arrays :( ...
    Realized my mistake :)
    Thanks everyone!