Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

problem with Array of Arrays

by Anonymous Monk
on Nov 09, 2015 at 17:59 UTC ( [id://1147271]=perlquestion: print w/replies, xml ) Need Help??

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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1147271]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found