http://www.perlmonks.org?node_id=312293


in reply to Re: Re^2: Balancing Coding Time And Code Quality
in thread Balancing Coding Time And Code Quality

Aha, I didn't realize that $_ was an alias within a map (greps as well then). Which makes a lot of sense if you take even half a second to think about it. I even threw together an example to prove it to myself.

# because $_ is an alias, @foo is also modified my @foo = qw/one two three four five six/; my @bar = map { s/[aeiou]//g; $_ } @foo; print join(', ', @foo), $/; # because we localize $_, @foo is not modified my @foo = qw/one two three four five six/; my @bar = map { local $_ = $_; s/[aeiou]//g; $_ } @foo; print join(', ', @foo), $/; # not to mention even when you loop through an array my @foo = qw/one two three four five six/; s/[aeiou]//g for @foo; print join(', ', @foo), $/;