Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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
Replies are listed 'Best First'.
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 making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2015-07-08 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls