Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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 http://perldoc.perl.org/functions/map.html

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($_)} = $_; }

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2016-10-01 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (574 votes). Check out past polls.