Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Simplifying for loop and applying multiple push function

by davido (Cardinal)
on Dec 14, 2005 at 21:16 UTC ( [id://516766]=note: print w/replies, xml ) Need Help??


in reply to Simplifying for loop and applying multiple push function

Just because someone said it can't be done in one line, I had to try:

use warnings; use strict; my %hash = ( 1 => 'one' , 2 => 'two' , 3 => 'three' ); # Here is the one line! my( @one ) = @hash{ my( @two ) = keys %hash }; # This line is just to demonstrate it worked. print map { "$two[$_] => $one[$_]\n" } 0 .. $#two;

Turns out you can do it in one with a slice. Roy_Johnson's approach deserves a ++ though, since it is actually legible. :)


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found