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 };
In reply to Re^2: Parsing attributes in one line using map
by jhourcle
in thread Parsing attributes in one line using map
by ruoso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |