in reply to Just when you thought you'd got it: 'foreach $f (@foo)' vs 'foreach (@foo)'

while (<$FH>) modifies global variable $_. Whenever you modify a global variable, localize it!
sub suck_this { my ($what) = @_ ; open my $FH, '<', \$what ; print " Read:" ; local $_; while (<$FH>) { s/\r/\\r/g ; s/\n/\\n/g ; print " '$_'" ; } ; print "\n" ; } ;

Replies are listed 'Best First'.
Re^2: Just when you thought you'd got it: 'foreach $f (@foo)' vs 'foreach (@foo)'
by blazar (Canon) on Oct 16, 2008 at 10:50 UTC

    I personally believe that it would be very, very fussy of me to remind it, but just for completeness, it has to be said that there is a well known bug with localising $_ and tied objects, which -I just tested- is still there in 5.10.0 (while I had hoped for it to have been solved...) But then of course one has not to worry unless she's using tied objects...

    --
    If you can't understand the incipit, then please check the IPB Campaign.

      Worse. There are two bugs associated with local $var and neither is specific to $_. I wrote about them.