in reply to Get AoH values into array

my @husbands = map { $_->{husband} } @AoH;

See map for more info

Replies are listed 'Best First'.
Re^2: Get AoH values into array
by starX (Chaplain) on Sep 06, 2007 at 18:23 UTC
    This may be a newbish question, but according to the map perldoc...
    %hash = map { getkey($_) => $_ } @array; is just a funny way to write %hash = (); foreach $_ (@array) { $hash{getkey($_)} = $_; }
    So doesn't map still solve the problem by using a loop? And wouldn't all the inefficiencies of using a loop directly be carried over by using map?

    Honest questions, I'm genuinely curious.

      Unless you want a recursive solution, there will be a loop, either explicity with for, while etc, or implicitly with map, grep etc.

      Some people (but not me) might prefer something like:

      my @husbands = husbands( @AoH ); sub husbands { my $this = shift; return ( $this->{husband}, husbands( @_ ) ) if @_; return $this->{husband}; }

      Look Ma, no loops!