Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Answer: How do I test for a blank line when reading from a file?

by thanos1983 (Vicar)
on May 29, 2014 at 21:01 UTC ( #1087875=categorized answer: print w/replies, xml ) Need Help??

Q&A > files > How do I test for a blank line when reading from a file? - Answer contributed by thanos1983

Extending runrig's answer to cover the case where "blank" could include whitespace characters (as merlyn's answer already does, negatively): Use /^\s*$/
As in:

while (<>) { print "blank line detected\n" if /^\s*$/; }

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2018-10-16 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (87 votes). Check out past polls.

    Notices?