beej has asked for the wisdom of the Perl Monks concerning the following question:

I have been writing a fairly simple script that will read through a directory of files and then search for the first like of that file (assuming all are text, which they are). However some of the files have blank lines (or carriage returns) as the starting line, so I have directed my perl script to skip over the blank lines...if only it would. I have tried the 2 following things, both which seem not to work:
if($_ =~ /^\s*$/){...} OR if($_ eq "\n") {...}
The $_ is a line read-in from a text file. The previous examples are not the most elegant way to do this, but nothing seems to work at this point. any advice?

Edit Masem 2001-07-13, Title change from "blank-ity blank blank!#$@!"

Replies are listed 'Best First'.
Re: blank-ity blank blank!#$@!
by davorg (Chancellor) on Jul 13, 2001 at 20:33 UTC
Re: blank-ity blank blank!#$@!
by adamsj (Hermit) on Jul 13, 2001 at 20:36 UTC
    I like this:

    CROP: while (<FH>) { m#^\s*$# ? next CROP : last CROP; } # Your code here, now that the blank lines are gone

    adamsj

    They laughed at Joan of Arc, but she went right ahead and built it. --Gracie Allen

Re: blank-ity blank blank!#$@!
by Wookie (Beadle) on Jul 13, 2001 at 21:01 UTC
    If you just wanna skip straight past the files with those kind of filenames:
    if ($_ =~ m/^\w.*$/) { # Process }
    And that will mean you only process files that start with a letter, number or underscore.