in reply to Re: Get AoH values into array
in thread Get AoH values into array

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.

Replies are listed 'Best First'.
Re^3: Get AoH values into array
by FunkyMonk (Bishop) on Sep 06, 2007 at 18:39 UTC
    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!