Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Iterating over verbatim hash reference

by ikegami (Patriarch)
on Jan 21, 2010 at 19:16 UTC ( [id://818798]=note: print w/replies, xml ) Need Help??


in reply to Iterating over verbatim hash reference

Here are four very simple/clean syntaxes to choose from:

  • { my %h = ( x=>5, y=>8 ); while ( my ($r,$s) = each %h ) { ... } }
  • for ({ x=>5, y=>8 }) { while ( my ($r,$s) = each %$_ ) { ... } }
  • for (paired( x=>5, y=>8 )) { my ($r,$s) = @$_; ... }
    where paired is defined as
    sub paired { my @pairs; push @pairs, [ shift, shift ] while @_; return @pairs; }
  • paired { my ($r,$s) = @_; ... } ( x=>5, y=>8 );
    where paired is defined as
    sub paired(&@) { my $cb = shift; my @rv; push @rv, $cb->(shift, shift) while @_; return @rv; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found