jzb has asked for the wisdom of the Perl Monks concerning the following question:

Why does the following work in perl 5.8.3 and not 5.005_03?
sub change_me{ local $^I = ".bak"; local *ARGV; @ARGV = "some_file"; while (<>) { s/foo/bar/i; print; } }

Replies are listed 'Best First'.
Re: In place edit 5.005_03 vs 5.8.3
by bart (Canon) on Apr 28, 2006 at 20:40 UTC
    Does it work without the line local *ARGV;?

    I remember a bug in an older perl where @ARGV, or is it the ARGV file handle, lost its magic when you localized the glob. But I don't remember if that was still so in 5.005.

    Update: I've looked up the thread that I remember, as I was in it. It's here: Re: A buggy intersection-method. Look at the date: Jun 23, 1999.

    Now look at the date of perl 5.005_03: Mar 28, 1999. That's just a few months earlier. So yes, that bug should still be in 5.005_03.

      Yes, but it breaks the flow if there is another variable. See here:
      sub change_me{ $myvar = somesub(); local $^I = ".bak"; @ARGV = "some_file"; while (<>) { s/foo/$myvar/i; print; } }
      This code hangs. I just can't wrap my head around what happens to $myvar. If this is a static entry (like above) it completes.
        Is there a way to get 5.005_03 to use the variable and not hang?