[San-Diego-pm] map HoAoA

Mike McClain mike.junk at nethere.com
Thu Oct 7 10:40:43 PDT 2010


    First let me say that this is self assigned homework just for my
own education, I'm not in class.
    Reading perldsc and perllol I thought to pull the second item from
each array of a HoAoA (hash of arrays of arrays) using a map statement
but after several days of flailing still haven't found a solution nor
do I even understand why I'm not getting what I want.
    Here's a code segment, strict and warnings are turned on just not
shown.

{   my %HoAoA = (
                a => [ [ qw / aa1 aa2 / ], [ qw / ab1 ab2 / ] ],
                b => [ [ qw / ba1 ba2 / ], [ qw / bb1 bb2 / ] ],
                c => [ [ qw / ca1 ca2 / ], [ qw / cb1 cb2 / ],
                       [ qw / cc1 cc2 / ] ],
                );

    #   this gets refs to all arrays
    my @aRefs = map { @{ $HoAoA{$_} } [ 0..$#{ $HoAoA{$_} } ] }  keys %HoAoA ;
    #   pull second entry from each array
    for my $a ( @aRefs )
    {   print "$a = $$a[1]\n";
    }

    #   This is the statement I'm having trouble with:
    #   If you can explain why I'm only getting the second entry from the
    #   last array of each hash entry then perhaps I can figure out how
    #   to get the second entry from all arrays
    my @seconds = map { @{ $HoAoA{$_} } [ 0..$#{ $HoAoA{$_} } ]->[1] }
                                                                keys %HoAoA ;
    print "\@seconds = @seconds\n";
}

Thanks,
Mike McClain
-- 
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org


More information about the San-Diego-pm mailing list