On Wed, Oct 13, 2010 at 08:33:57AM +0200, Shlomi Fish wrote:
<snip> 
> On Wednesday 13 October 2010 06:39:03 Mike McClain wrote:
> > Why do @arrays and @seconds not have the same number of elements?
> >     my @arrays =
> >         map
> >         { @{ $HoAoA{$_} } [ 0..$#{ $HoAoA{$_} } ] }
> >         keys %HoAoA ;
> 
> This is equivalent to:
> map { @{$HoAoA{$_} } } keys(%HoAoA);
> 
> Which flattens all the arrays into one big list. It can be written better as:
> map { @$_ } values(%HoAoA);
> 

Thanks I hadn't seen that.

> >     my @seconds =
> >         map  { @{ $HoAoA{$_} } [ 0..$#{ $HoAoA{$_} } ]->[1] }
> >         keys %HoAoA ;
> 
> That's wrong. What it does is create an array, evaluate it in scalar context 
> and then trying to use it as an array refand extract the second element. 
> Doing 
> @{$array_re...@indices]->[$idx] is a strange construct which makes no sense.

It's right because it complies and executes with no errors.
It's only wrong because it doesn't give me what I wanted.
What I still don't understand is why it gives me what it does.

> What you want based on your comment is :

Turns out what I wanted (with thanks to merlyn) is:
my @seconds = map { $_->[1] } map { @$_ } values %HoAoA;

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

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to