Search notes:

Perl function: map

map can be used to apply a function to each element in a list.
The function is simialar in spirit like the equally named Python function.
#!/usr/bin/perl

#
#   Note the special parsing rule for map:
#   curly braces don't create a hash.
#
use warnings;
use strict;

my @words = qw(one two three four five);

#
# Use map to create uppercase versions of the
# elements in a list:
#
my @uppercase_words = map {uc} @words;

print join "\n", @uppercase_words;
#
# ONE
# TWO
# THRE
# FOUR
# FIVE

# -------------------------------------

print "\n--\n";

#
# Check each element and return a translation if available
#
my @words_german = map { $_ eq 'one'   and 'eins' or
                         $_ eq 'two'   and 'zwei' or
                         $_ eq 'three' and 'drei' or
                         $_ eq 'four'  and 'four' or
                        '?'}  @words;

print join "\n", @words_german;
#
# eins
# zwei
# drei
# four
# ?
Github repository about-perl, path: /functions/map.pl

See also

Perl functions
map seems to roughly correspond to the R function sapply().
Common first class function: map

Index