Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Help with a regular expression for file name parsing

by bontchev (Sexton)
on Dec 07, 2011 at 12:01 UTC ( [id://942232]=note: print w/replies, xml ) Need Help??


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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: Help with a regular expression for file name parsing
by BrowserUk (Patriarch) on Dec 07, 2011 at 19:08 UTC
    Any better suggestions?

    For you, no. At least none that would be considered polite.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      For you, no. At least none that would be considered polite.

      Too bad. Then either you or I have come to the wrong place.

        Then either you or I have come to the wrong place.

        Hm. I've been hanging around here for the best part of a decade. What does that tell you?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re^3: Help with a regular expression for file name parsing
by Anonymous Monk on Dec 07, 2011 at 12:21 UTC

    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
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://942232]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-29 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found