Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Cleaning up a text file with compact regex

by chromatic (Archbishop)
on Apr 24, 2007 at 05:51 UTC ( [id://611655]=note: print w/replies, xml ) Need Help??


in reply to Cleaning up a text file with compact regex

open( my $fh, '<', 'file.txt' ) or die "Cannot read file.txt: $!\n"; # clearer idiom, anyone? scalar <$fh> for 1 .. 6; while (<$fh>) { next if /^;/; # ... process lines }

Replies are listed 'Best First'.
Re^2: Cleaning up a text file with compact regex
by betterworld (Curate) on Apr 24, 2007 at 09:49 UTC
    while (<$fh>)

    You should always put local($_); before such a loop, because the global variable $_ is set to each line and is not cleaned up in the end.

    Update: http://perl.plover.com/local.html has an example of the dangers of this kind of while loop.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found