Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl map ?

Status
Not open for further replies.

donny750

Programmer
Joined
Jul 13, 2006
Messages
145
Location
FR
hello,

I've read the perl doc for the function map but i've not good understood;

Somebody can explain me with an example , please ?

Thnaks for your help
 
It's just like a condensed foreach loop. if you cut and paste the following two examples, you'll see they do the same thing.
Code:
#!/usr/bin/perl

use strict;
use warnings;

my @array = qw(A b C D e);

my @mapped = map {lc} @array;

print join("\n", @mapped);
is just another way of writing
Code:
#!/usr/bin/perl

use strict;
use warnings;

my @array = qw(A b C D e);

my @mapped;

foreach (@array) {
   push @mapped, lc($_);
}

print join("\n", @mapped);
Does this help?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
yes thanks,
i understand
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top