On Oct 7, Dave Thacker said:

Given this test file.
------start---------
this

is

my file
--------end----------
I want to skip the blank lines and just print the lines with text, like this

When you say "blank", do you mean lines with NO characters at all (other than the ending newline) or lines that ONLY contain whitespace?

   chomp;
   next if ($_ =~ /^\s+/);

Ok, if the line is ONLY "\n", then if you chomp() it, the line will be the empty string, "". This means it WON'T be matched by /^\s+/.

Your regex doesn't make any sense to me. It would skip lines that start with a space, like " This one". And what's the use of looking for more than one leading space?

I have a couple possible solutions for you. If you want to skip lines that consist of ABSOLUTELY NOTHING other than a newline, then you can do:

  while (<FH>) {
    chomp;
    next if $_ eq "";
    ...
  }

If you want to skip lines that only have whitespace characters, then you can do:

  while (<FH>) {
    chomp;
    next unless /\S/;
  }

--
Jeff "japhy" Pinyan        %  How can we ever be the sold short or
RPI Acacia Brother #734    %  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %    -- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to