Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2018-07-16 05:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (332 votes). Check out past polls.

    Notices?