Evaluates an expression for each element of a list:
@words = map {split ' '} @lines;
Here is another example. The variable $_
is temporarily set
to each element of the list. Notice that the operation is destructive -
@arr
is changed.
my @arr = qw(1 2 3); my @new = map {$_ *= 2} @arr; print "@new, @arr\n"; # --> '2 4 6, 2 4 6'