Evaluates the BLOCK or EXPR for each element of LIST (locally setting$_
to each element) and returns the list value composed of the results of each such evaluation. Evaluates BLOCK or EXPR in a list context, so each element of LIST may produce zero, one, or more elements in the returned value.
In scalar context, returns the total number of elements so generated.
@chars = map(chr, @nums);
translates a list of numbers to the corresponding characters. And
%hash = map { getkey($_) => $_ } @array;
is just a funny way to write
%hash = (); foreach $_ (@array) {$hash{getkey($_)} = $_; }
Note that, because$_
is a reference into the list value, it can be used to modify the elements of the array. While this is useful and supported, it can cause bizarre results if the LIST is not a named array. Using a regularforeach
loop for this purpose would be clearer in most cases. See also"grep" for an array composed of those items of the original list for which the BLOCK or EXPR evaluates to true.
Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.