in reply to map-like hash iterator
see mugwumpjism's prior art in his response to the mapcar -- map for more than one list node.
code here for those too lazy to click above...
sub mapeach (&\%) { my $sub = shift; my $hash = shift or do { require Carp; Carp::croak( "mapeach: Nothing to map" ); }; my @ret; while ( my ($k, $v) = each %{$hash}) { local ($_) = $k; push @ret, $sub->($k, $v); } return wantarray ? @ret : { @ret }; }
~Particle *accelerates*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: map-like hash iterator
by jdporter (Paladin) on Nov 07, 2002 at 00:00 UTC |