Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: map-like hash iterator

by particle (Vicar)
on Nov 06, 2002 at 23:32 UTC ( #210960=note: print w/ replies, xml ) Need Help??


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*


Comment on Re: map-like hash iterator
Select or Download Code
Re: Re: map-like hash iterator
by jdporter (Canon) on Nov 07, 2002 at 00:00 UTC

    Prior art? He posted that on 2001-11-30. My post to FWP was on 2001-03-29.

Reaped: Re^2: map-like hash iterator
by NodeReaper (Curate) on Apr 16, 2010 at 02:44 UTC

      what do you mean, you "get nothing"? Note that you have to have some stuff in your %h hash or you will indeed get no output from the sample code...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://210960]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-07-13 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (249 votes), past polls