Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do I remove blank lines from text files?

by chromatic (Archbishop)
on Jul 10, 2000 at 23:09 UTC ( #21849=note: print w/replies, xml ) Need Help??


in reply to How do I remove blank lines from text files?

Don't forget that our friend next will work in a while loop. Combining some of these answers gets you the technique I prefer:
while (<FILE>) { next if /^#/; # skip lines starting with comments next unless /\S/; # do something with a real line here }
This allows you to use a normal loop construct (makes sense to me) and short-circuit it at the beginning if certain conditions are met. It makes cleaner code than a lot of if-elsif statements.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2020-10-20 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (210 votes). Check out past polls.

    Notices?