Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by chromatic (Archbishop)
on Jul 10, 2000 at 23:09 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://21849]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (12)
As of 2024-04-16 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found