Perl map() Function

What is map() Function in Perl programming?

Explanation

The map() function applies a change to a list to get back a new list with the specified changes.

Syntax:


map EXPR,LIST;
map BLOCK,LIST;

In the above syntax, map() function takes a function or expression and a list as arguments.

Example :


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
@color = ('Green','Orange','Blue','Pink','Peach','Black');
@colmap = map(uc, @color);
foreach $key (@colmap)
{
print "$keyn";
}
Result :

GREEN ORANGE BLUE PINK PEACH BLACK

In the above example all the elements of the array "@color" is converted to uppercase and stored in another array using the map() function.All the elements of the array is printed using a loop.

Ask Questions

Ask Question