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

Hi Monks
I seem to be stuck with a very simple problem apparently, but to me it doesn't work for some reason. So, say you have the AoA like the following:
@AoA = ( [ "fred", "barney" ], [ "george", "jane", ], [ "homer", "marge", ] );
how can I, using a for loop, print only the second column (i.e. barney jane and marge)?

Replies are listed 'Best First'.
Re: problem with Array of Arrays
by toolic (Bishop) on Nov 09, 2015 at 18:02 UTC
    perldsc
    use warnings; use strict; my @AoA = ( [ "fred", "barney" ], [ "george", "jane", ], [ "homer", "marge", ] ); for my $aref (@AoA) { print $aref->[1], ' '; } print "\n"; __END__ barney jane marge
Re: problem with Array of Arrays
by kennethk (Abbot) on Nov 09, 2015 at 18:03 UTC
Re: problem with Array of Arrays
by AnomalousMonk (Archbishop) on Nov 09, 2015 at 18:54 UTC
      Thanks so much guys!
Re: problem with Array of Arrays
by muba (Priest) on Nov 10, 2015 at 14:46 UTC

    Just for TIMTOWTDI's sake, you could do without a for loop, although the dereferencing principle remains the same.

    print join ", ", map {$_->[1]} @AoA;