in reply to What Is Going On Here ?????

This is why subroutines that use $_ should always begin with local $_;:
sub do_something { local $_; ... }
will fix the problem.

Replies are listed 'Best First'.
(tye)Re: What Is Going On Here ?????
by tye (Sage) on Nov 21, 2000 at 22:35 UTC

    I just wanted to emphasize that this is a really important point that will save you from the kinds of bugs that can take forever to track down.

    With modern Perls, you can skip the local $_ if you only ever use $_ as a loop variable, but better to be safe if you aren't sure.

    Update: Note that this doesn't apply to while loops (which don't have a loop variable in my book) as nicely pointed out by autark in Re: What Is Going On Here ?????.

            - tye (but my friends call me "Tye")