in reply to Re^2: Hash assignments using map
in thread Hash assignments using map
... I thought I could do the same thing using map ...my @to_keep = qw{ a c }; my %keepers; foreach ( @to_keep ) { $keepers{$_}++; }
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.
|
|---|