and tested, though i had forgot to escape an \ in [^\\s]
#!/usr/bin/perl --
#~ 2011-12-07-04:10:56PDT by Anonymous Monk
#~ perltidy -csc -otr -opr -ce -nibc -i=4
use strict;
use warnings;
use autodie; # dies if open/close... fail
Main( @ARGV );
exit( 0 );
sub Main {
if ( @_ == 2 ) {
NotDemoMeaningfulName(@_);
} else {
Demo();
print '#' x 33 ,"\n", Usage();
}
} ## end sub Main
sub NotDemoMeaningfulName {
my ( $inputFile, $outputFile ) = @_;
open my ($inFh), '<', $inputFile;
open my ($outFh), '>', $outputFile;
while( defined( my $data = <$inFh>) ){
print $outFh "$_\n"
for $data =~ m~
\@include
\s+
(
(?: '[^']*' )
|
(?: "[^"]*" )
|
(?:
(?:\\.)
|
[^\\\s]
)+
)
~xg;
#~ for $data =~ m[\@include\s('[^']+'|"[^"]+"|.+?(?<!\\))\
+s]g;
# /\@include\s+('[^']+'|"[^"]+"|.+?(?<!\\))\s+
+/g
}
close $inFh;
close $outFh;
} ## end sub NotDemoMeaningfulName
sub Usage {
<<"__USAGE__";
$0
$0 dataFile newDataFile
__USAGE__
} ## end sub Usage
sub Demo {
my ( $Input, $WantedOutput ) = DemoData();
NotDemoMeaningfulName( \$Input, \my $Output );
require Test::More;
Test::More::is(
$Output,
$WantedOutput,
' NotDemoMeaningfulName Works Aas Designed'
);
Test::More::done_testing();
print "\n$Output\n";
} ## end sub Demo
sub DemoData {
#~ http://perlmonks...
my $One = <<'__One__';
@include test
#some "random stuff" @include "some file" did you parse that?
#more 'random' stuff @include 'another file' you sure?
#and more random stuff @include yet\ another\ file positive?
__One__
#~ http://perlmonks...
my $Two = <<'__Two__';
test
"some file"
'another file'
yet\ another\ file
__Two__
return $One, $Two;
} ## end sub DemoData
__END__
$ perl pm.re.942167.pl
ok 1 - NotDemoMeaningfulName Works Aas Designed
1..1
test
"some file"
'another file'
yet\ another\ file
#################################
pm.re.942167.pl
pm.re.942167.pl dataFile newDataFile
|