To get what you want, you need to localize $_ and reuse it as the last expression evaluated in the block:my @in = qw(aaa bbb ccc); my @out = map { local $_ = $_; s/.$/x/; $_ } @in; print "@in\n=>\n@out\n";
Or use a proper lexical variable:
my @out = map { (my $s = $_) =~ s/.$/x/; $s } @in;
AIUI in blead/5.10 the following should also work just in the same manner:
my $_; # ... my @out = map { s/.$/x/; $_ } @in;
In reply to Re^2: Using regex in Map function
by blazar
in thread Using regex in Map function
by narashima
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |