Perl: the Markov chain saw | |
PerlMonks |
Re: while(<>) { ... } considered harmfulby dws (Chancellor) |
on Sep 07, 2002 at 23:37 UTC ( [id://195930]=note: print w/replies, xml ) | Need Help?? |
Since
map { substr($_, 1, 1) = "foo" } qw(bar baz);
and
grep { substr($_, 1, 1) = "foo" } qw(bar baz);
both exhibit the problem you've observed, perhaps the advice might better be phrased
Don't write to $_ from within map { } or grep { }local $_; is one way to avoid writing to it, since the 'it' is now different.
In Section
Meditations
|
|