Jerry said:
I do not understand this at all:
local( *FI );
open( FI, $file ) || die "cannot open input file $file: ";
while(<FI>) { # I get "Modification of a read-only value attempted at
$file this line"
I have done this countless number of times. What is going on?
The while(<HANDLE>) construct does not localize $_ it stomps all over
whatever's happens to be in $_. Since $_ is typically an alais to
something else it also stomps all over that something else. If you are
lucky then the something else is a reaonly value and you get an error
rather than random corruption of another variable.
Some people will tell you to localize $_ beforehand using local($_) but
this is not safe. Thay are wrong, do not do that. If anyone ever tells
you to do that then tell them that they are wrong. local($_) does nasty
things when $_ happens to be an alias to an element of a tied agregate.
If you want to use this technique (other than at the top-level of very
small scripts, and particularly within subroutines) then you should
local(*_) beforehand. This, unfortunately will make @_ inaccessible so
make sure you've got everything you need from it first.