Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL map Function



Syntax

map EXPR, LIST

map BLOCK LIST


Definition and Usage

Evaluates EXPR or BLOCK for each element of LIST. For each iteration, $_ holds the value of the current element, which can also be assigned to allow the value of the element to be updated.

Simply, Perl's map() function runs an expression on each element of an array, and returns a new array with the results.

Return Value

  • In scalar context, returns the total number of elements so generated.

  • In list context, returns list of values

Example

Try out following example:

#!/usr/bin/perl -w

@myNames = ('jacob', 'alexander', 'ethan', 'andrew');
@ucNames = map(ucfirst, @myNames);

foreach $key ( @ucNames ){
 print "$key\n";
}

It will produce following results:

Jacob
Alexander
Ethan
Andrew


Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names