Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Reii: Should we Localize $_ ?

by dragonchild (Archbishop)
on Jun 13, 2001 at 23:52 UTC ( [id://88188]=note: print w/replies, xml ) Need Help??


in reply to Re: Reii: Should we Localize $_ ?
in thread Should we Localize $_ ?

Try the following with and without the 'local $_;' line and you'll see what he's talking about.

use strict; sub getfile { local $_; my $filename = shift; local *F; open F, "< $filename" or die "Couldn't open `$filename': $!"; my $contents; while (<F>) { s/#.*//; # Remove comments next unless /\S/; # Skip blank lines $contents .= $_; # Save current (nonblank) line } return $contents; } my @array = ("base_tester", "Foo.pm"); foreach (@array) { my $filename = $_; my $f = getfile($filename); } print "@array\n";
That's what I tried to see the effects, and I was rather surprised.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://88188]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-25 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found