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

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

by bravismore (Initiate)
on Oct 11, 2000 at 20:50 UTC ( [id://36246]=perlquestion: print w/replies, xml ) Need Help??

bravismore has asked for the wisdom of the Perl Monks concerning the following question: (files)

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

Originally posted as a Categorized Question.

  • Comment on How do I test for a blank line when reading from a file?

Replies are listed 'Best First'.
Re: How do I test for a blank line when reading from a file?
by merlyn (Sage) on Oct 11, 2000 at 20:54 UTC
    print "it's blank" unless /\S/;
    (This assumes that a line consisting of only whitespace characters is considered blank.)
Re: How do I test for a blank line when reading from a file?
by thanos1983 (Parson) on May 29, 2014 at 21:01 UTC

    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*$/; }

Re: How do I test for a blank line when reading from a file?
by runrig (Abbot) on Oct 11, 2000 at 20:52 UTC
    If by "blank" you mean "empty", then /^$/, as in:
    while (<>) { print "blank line detected\n" if /^$/; }
Re: How do I test for a blank line when reading from a file?
by abhishek_akj (Initiate) on Aug 26, 2009 at 10:28 UTC
    while (<>) { print __LINE__ " | This line is blank\n" if /^$/; }
    A little friendlier output

    Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-16 11:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found