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

Re^3: Hash assignments using map

by graff (Chancellor)
on Feb 24, 2007 at 22:45 UTC ( [id://601928]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Hash assignments using map
in thread Hash assignments using map

my @to_keep = qw{ a c }; my %keepers; foreach ( @to_keep ) { $keepers{$_}++; }
... I thought I could do the same thing using map ...

The way to do that with map would be like this:

my %keepers = map { $_ => 1 } @to_keep;

The point is that, in this case, you want each iteration in map to return a key/value pair, not just a single value, and the "fat comma" (=>) does that for you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found