On Jul 15, Randy W. Sims said: >[I see this a lot on these groups. I know most of the time it is just >used for examples, but I thought I would point out that it is a bad habit.] > >Anytime you make a direct assignment to the special variable $_, you >should local-ize it. This code demonstrates the problem:
I have "better" code that demonstrates the problem: # scans a file for a string sub scanf { my ($file, $string) = @_; open F, "< $file"; while (<F>) { return 1 if /\Q$string/; } close F; return; } for (@files) { if (scanf($_, "some string")) { push @matches, $_; } } Using the <FH> operator implicitly assigns to $_, without localizing it. Therefore, if you're going to use 'while (<FH>)', please local()ize $_ first. -- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ % -- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>