... 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.
In reply to Re^3: Hash assignments using map
by graff
in thread Hash assignments using map
by njcodewarrior
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |