Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Cleaning up a text file with compact regex

by chromatic (Archbishop)
on Apr 24, 2007 at 05:51 UTC ( #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: has an example of the dangers of this kind of while loop.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2021-06-24 16:29 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (130 votes). Check out past polls.