In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/f94762723eddc4a0de865db28c07e020aecf8d06?hp=12916dad38433a42694da808e8ec9eafc149f1c8>
- Log ----------------------------------------------------------------- commit f94762723eddc4a0de865db28c07e020aecf8d06 Author: Alexander Hartmaier <abra...@cpan.org> Date: Fri Feb 11 15:36:21 2011 +0100 perldoc improvements for map M pod/perlfunc.pod commit 14cca8c3de3e3a27586eea0be45a1e045981c98d Author: Father Chrysostomos <spr...@cpan.org> Date: Sun Feb 13 11:39:58 2011 -0800 Add Alexander Hartmaier to AUTHORS M AUTHORS ----------------------------------------------------------------------- Summary of changes: AUTHORS | 1 + pod/perlfunc.pod | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 93b7a13..deef7d1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -40,6 +40,7 @@ Albert Chin-A-Young <ch...@thewrittenword.com> Albert Dvornik <b...@alum.mit.edu> Alessandro Forghieri <a...@orion.it> Alexander Alekseev <a...@alemate.ru> +Alexander Hartmaier <abra...@cpan.org> Alexei Alexandrov <alexei.alexand...@gmail.com> Alex Davies <adav...@ptc.com> Alex Gough <a...@rcon.org> diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index ece1005..d85b3d7 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -2996,9 +2996,26 @@ total number of elements so generated. Evaluates BLOCK or EXPR in list context, so each element of LIST may produce zero, one, or more elements in the returned value. - @chars = map(chr, @nums); + @chars = map(chr, @numbers); -translates a list of numbers to the corresponding characters. And +translates a list of numbers to the corresponding characters. + + my @squares = map { $_ * $_ } @numbers; + +translates a list of numbers to their squared values. + + my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers; + +shows that number of returned elements can differ from the number of +input elements. To omit an element, return an empty list (). +This could also be achieved by writing + + my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers; + +which makes the intention more clear. + +Map always returns a list which can be assigned to a hash where the elements +become key/value pairs. See L<perldata> for more details. %hash = map { get_a_key_for($_) => $_ } @array; -- Perl5 Master Repository