On 7/1/07, Mark Jason Dominus wrote: > >Dave Mitchell: >> NB - It has traditionally been the case that 'local $_' >> was unsafe, and that it was better to do 'local *_' >> instead. Can anyone remind me why this is, and I'm >> wondering whether the assorted local() fixes have made >> this point moot. > > tie $x, "DO_NOT_MODIFY"; > sub DO_NOT_MODIFY::TIESCALAR { bless [] => $_[0] } > sub DO_NOT_MODIFY::FETCH { return rand; } > sub DO_NOT_MODIFY::STORE { > # system("do-bad-stuff"); > die("I told you not to modify this!") > } > > for ($x) { > use_dollar_underbar(); > } > > sub use_dollar_underbar { > local $_; > print "okay...\n"; > $_ = 1; > } > > > use_dollar_underbar() wants to operate on $_ without > tampering with its global value and without causing > any strange action-at-a-distance. So it uses "local $_" > to try to do this. But "local $_" *itself* tampers > with the global value and causes a strange > action-at-a-distance. And more specifically... Changing it to confess() instead of die shows that local $_; calls DO_NOT_MODIFY::STORE(). Yves -- perl -Mre=debug -e "/just|another|perl|hacker/"