in reply to Why localize $_ in the map block?
in thread how could I use map here?
Without the local the original array is changed. Since $_ is aliased to each element the s// changes the original array. Try:
my @x = qw(foo bar CHOP_ME_OFF_foo); my @y = @x; my @copies = map { local $_ = $_; s/^CHOP_ME_OFF_//; $_ } @x; my @changes = map {s/^CHOP_ME_OFF_//; $_ } @y; print "x @x\ny @y\ncopies @copies\nchanges @changes\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Why localize $_ in the map block?
by pike (Monk) on Feb 10, 2003 at 16:30 UTC |