[prog] Perl vars and local

Dan dan at cellectivity.com
Mon Apr 11 20:28:13 EST 2005


It seems to me that special Perl variables, especially $_, should be
declared with "local" at the beginning of subroutines, but that I don't
see people doing it very much.

It seems to me that the caller of a function shouldn't have to worry
about global variables being modified. For example:

  while ( <> ) {
    s/foo/bar/;
    DoSomethingElse();    # Did this modify $_ ?
    print;
  }

But, again, I don't see Perl programmers using "local" very much, even
when they change $_. Are they using bad style, or is there something I'm
not getting?

-- 
  I have a nice home, the office is close by, and the pay is good.
         - John F. Kennedy, on what it's like to be President




More information about the Programming mailing list