Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Write code diferently

by Random_Walk (Prior)
on Aug 23, 2013 at 10:27 UTC ( #1050624=note: print w/replies, xml ) Need Help??

in reply to Write code diferently

You can replace map with a for loop and an assignment. There is an example of allocation to a hash with both map and a loop to be found in the map documentation

From Perldoc

Map always returns a list, which can be assigned to a hash such that the elements become key/value pairs. See perldata for more details.

%hash = map { get_a_key_for($_) => $_ } @array;

is just a funny way to write

%hash = (); foreach (@array) { $hash{get_a_key_for($_)} = $_; }


Pereant, qui ante nos nostra dixerunt!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1050624]
[LanX]: unusual that "Pimp my Bride" never made it into TV (?)
LanX sighs ... no idea stupid enough
[choroba]: "Smack My Bitch Up" did, though
[Eily]: that's the internet for you LanX
[Eily]: and I'm pretty sure there's a rule somewhere that states that the stupider the idea, the more likely it is to already have been done

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2017-03-27 15:18 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.