Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Write code diferently

by Random_Walk (Parson)
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!


Comment on Re: Write code diferently
Select or Download Code

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 imbibing at the Monastery: (9)
As of 2014-08-28 11:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls