DO_SOMETHING_WITH-$_
####
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @array = qw{a b c};
my @new_array = map{my $letter = $_; ++$letter} @array;
print "before: @array\n";
print "after: @new_array\n";
# with some extra white space
# it looks even more 'inside-out' :-)
my @another = map{
my_func()
} @new_array;
print "another: @another\n";
print "original \@array: @array\n";
sub my_func {
my $letter = $_;
$letter++;
return $letter;
}
exit;
# DO_SOMETHING_WITH-$_
# doesn't work on a list
for (qw{a b c}){
# this line generates:
# "Modification of a read-only value attempted at..."
++$_;
}
# so does this
map {++$_} qw{a b c};
####
---------- Capture Output ----------
> "C:\Perl\bin\perl.exe" _new.pl
before: a b c
after: b c d
another: c d e
original @array: a b c
> Terminated with exit code 0.