Hi;

  I need to find Makefiles that contain a backslash line continuation
character followed by a blank (or whitespace only) line.  I tried a
regular expression first but just couldn't get it right.  I then tried
comparing by a pair of strings, but that isn't right either.

First try:
############################################
#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;

my $valid_string = "sample text\\n second line is valid\n";
my $invalid_string = "sample text \\n   \n";
if ($invalid_string =~ m|\\\n\W$|) {
    print "INVALID\n" ;
} else {
    print "valid\n";
}
if ($valid_string =~ m|\\\n\W$|) {
    print "INVALID\n" ;
} else {
    print "valid\n";
}
############################################

Second try:
############################################
#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;

foreach my $file (@ARGV) {
    open (MAKEFILE, $file) or die "ERROR: Unable to open " . $file . "
for reading, $!";
    my $line_before = "";
    my $linecount;
    while (my $line = <MAKEFILE>) {
        chomp $line;
        $linecount++;
        print "DEBUG: " . ($linecount-1) . " line (before)  = |" .
$line_before . "|\n";
        print "DEBUG: " . $linecount     . " line (current) = |" . $line
. "|\n\n";
        if ($line_before =~ m|\\$|) {
            print $file . " has a backslash continuation to a following
blank line at or near line " . $linecount . "\n" if ($line =~ m|^\W*$|);
        } else {
            $line_before = $line;
        }
    }
    close (MAKEFILE);
}
############################################

The first one reports both strings as valid, so the regex is wrong?

The second one incorrectly reports that all Makefiles have one or more
lines with continuation (\) characters at the end of the line followed
by a blank (or whitespace only) line.

Please help,
Thanks in advance,
Ken Wolcott



-- 
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