in reply to while(<>) { ... } considered harmful
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.
Update: Hm.. It's a bit worse than that.
foreach ( qw(foo) ) { $_ = 1 }
also exhibits the problem.
|
---|
In Section
Meditations