For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2004 > Re: finding Makefiles which containing a backslash continuation character









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: finding Makefiles which containing a backslash continuation character
John W. Krahn

2004-08-04, 3:55 am

Ken Wolcott wrote:
> Hi;


Hello,

> 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.
>
> [snip code]


This will do what you want:

#!/usr/bin/perl
use strict;
use diagnostics;

while ( <> ) {
my $line_num = $.;
if ( /\\\s*$/ ) {
my $line_before;
if ( ( $line_before = <> ) =~ /^\s*$/ ) {
print "$ARGV has a backslash continuation to a following blank line at line $line_num\n";
}
else {
$_ = $line_before;
redo;
}
}
}

__END__



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com