FAQ
I have to write a script that processes text in a
file. The text includes lots of blank lines. How can
I tell Perl to skip the lines? I thought maybe
something like:

next if ($line =~ /\s+/);

However, what if the line simply happens to have more
than one whitespace. Even a sentence has whitespace
between the words! Or maybe the line is idented!





=====
"I'm the last person to pretend that I'm a radio. I'd rather go out and be a color television set."
-David Bowie

"Who dares wins"
-British military motto

"The freak is the norm." - "The Infernal Desire Machines of Dr. Hoffman" by Angela Carter

Search Discussions

  • Mallik at Dec 14, 2004 at 5:47 am
    Its simple.

    next if ($line =~ /^\s*$/);

    Mallik.

    -----Original Message-----
    From: Christopher Spears
    Sent: Tuesday, December 14, 2004 11:14 AM
    To: beginners@perl.org
    Subject: regexp for a blank line


    I have to write a script that processes text in a
    file. The text includes lots of blank lines. How can
    I tell Perl to skip the lines? I thought maybe
    something like:

    next if ($line =~ /\s+/);

    However, what if the line simply happens to have more
    than one whitespace. Even a sentence has whitespace
    between the words! Or maybe the line is idented!





    =====
    "I'm the last person to pretend that I'm a radio. I'd rather go out and be
    a color television set."
    -David Bowie

    "Who dares wins"
    -British military motto

    "The freak is the norm." - "The Infernal Desire Machines of Dr. Hoffman" by
    Angela Carter

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • Dave Gray at Dec 14, 2004 at 4:47 pm

    Christopher Spears wrote:
    I have to write a script that processes text in a
    file. The text includes lots of blank lines. How can
    I tell Perl to skip the lines?
    On Tue, 14 Dec 2004 11:22:54 +0530, Mallik wrote:
    next if ($line =~ /^\s*$/);
    +1 - this will match "\n", " \n", "\t\n", "\t \n", etc
  • Raj, Raymond at Dec 14, 2004 at 5:51 am
    next if ($line =~ /^\s+$/);

    -----Original Message-----
    From: Christopher Spears
    Sent: Tuesday, December 14, 2004 11:14 AM
    To: beginners@perl.org
    Subject: regexp for a blank line


    I have to write a script that processes text in a
    file. The text includes lots of blank lines. How can
    I tell Perl to skip the lines? I thought maybe
    something like:

    next if ($line =~ /\s+/);

    However, what if the line simply happens to have more
    than one whitespace. Even a sentence has whitespace
    between the words! Or maybe the line is idented!





    =====
    "I'm the last person to pretend that I'm a radio. I'd rather go out and be
    a color television set."
    -David Bowie

    "Who dares wins"
    -British military motto

    "The freak is the norm." - "The Infernal Desire Machines of Dr. Hoffman" by
    Angela Carter

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • Bob Showalter at Dec 14, 2004 at 1:34 pm

    Christopher Spears wrote:
    I have to write a script that processes text in a
    file. The text includes lots of blank lines. How can
    I tell Perl to skip the lines? I thought maybe
    something like:

    next if ($line =~ /\s+/);

    However, what if the line simply happens to have more
    than one whitespace. Even a sentence has whitespace
    between the words! Or maybe the line is idented!
    next unless $line =~ /\S/; # skip unless it contains non-whitespace

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedDec 14, '04 at 5:44a
activeDec 14, '04 at 4:47p
posts5
users5
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase