Hi Mike,

On Wednesday 13 October 2010 06:39:03 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
> 

Reformatting due to my mailer's limitations:

> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> {
> 
>     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 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);

>     #   this only gets the second entry from the last array of each hash
>     # entry 
>
>     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.

What you want based on your comment is :

[code]
map { $_->[-1]->[1] } values(%HoAoA);
[/code]

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
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