Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 studying the Monastery: (7)
As of 2015-07-02 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (28 votes), past polls