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

Re^2: Parsing attributes in one line using map

by jhourcle (Prior)
on Sep 25, 2006 at 13:38 UTC ( #574732=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing attributes in one line using map
in thread Parsing attributes in one line using map

Returning more (or less even) elements than provided is very natural for map and very commonly used, especially for generating hashes ..

For those not familiar with returning less -- use an empty list (). To build on davidrw's example:

perl -MData::Dumper -le 'my %oddcubes = map { $_%2 ? ($_ => $_**3) : ( +) } 1..9; print Dumper \%oddcubes' $VAR1 = { '1' => 1, '3' => 27, '7' => 343, '9' => 729, '5' => 125 };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2021-01-27 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?