Mike McClain wrote:
I've looked at this for a few days but still can't see 'why'
I get what I do.
Why do @arrays and @seconds not have the same number of elements?
Thanks,
Mike
{ my %HoAoA = (
a => [ [ qw / aa1 aa2 / ], [ qw / ab1 ab2 / ] ],
b => [ [ qw / ba1 ba2 / ], [ qw / bb1 bb2 / ], [ qw / bc1 bc2 / ] ],
);
# this gets refs to all arrays
my @arrays = map { @{ $HoAoA{$_} } [ 0..$#{ $HoAoA{$_} } ] } keys %HoAoA ;
# this only gets the second entry from the last array of each hash entry
my @seconds = map { @{ $HoAoA{$_} } [ 0..$#{ $HoAoA{$_} } ]->[1] }
keys %HoAoA ;
print "\...@arrays = @arrays\n";
print "\...@seconds = @seconds\n";
}
@{ $HoAoA{$_} } [ 0..$#{ $HoAoA{$_} } ] is an array slice and
OBJECT->[1] dereferences OBJECT as if it were an array and accesses the
second element _however_ an array slice is not an array reference so
this won't work. Why it returns the last element of the last array is
beyond me. :-(
When you have ]->[ or ]->{ or }->[ or }->{ you can shorten that to ][ or
]{ or }[ or }{ which in your case will produce a syntax error.
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/