in reply to how to skip certain lines and check for blank ones?

I might do something like this:

use strict; use warnings; open my $infile, '<', 'sss.txt' or die $!; while( my $line = <$infile> ) { $line =~ /^$/ and die "Blank line detected at $.\n"; $line =~ /^#/ and next; print "$.: $line"; } close $infile;

The first regexp matches (thus triggering the die) if the line is empty, or empty with a newline character at the end.

The second regexp matches (thus skipping to the next line) if a '#' is found as the first character of the line.


Dave

Replies are listed 'Best First'.
Re^2: how to skip certain lines and check for blank ones?
by davorg (Chancellor) on Oct 31, 2006 at 09:27 UTC
    $line =~ /^$/ and die "Blank line detected at $.\n";

    Because people have differing opinions about what a blank line is, I'd probably replace that line with:

    $line =~ /\S/ or die "Blank line detected at $.\n";
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg