http://www.perlmonks.org?node_id=942237


in reply to Re^2: Help with a regular expression for file name parsing
in thread Help with a regular expression for file name parsing

Any better suggestions?

Learn to copy paste better :) because the regex you're using, isn't the same one BrowserUk posted

His regex works, despite him posting the code in the context of his REPL (Read Eval Print Loop), see RFC: IPerl - Interactive Perl ( read-eval-print loop ), Re^6: RFC: IPerl - Interactive Perl ( read-eval-print loop ) (x)

I checked

#!/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]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

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.