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
|
---|