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

Re^4: Parse::RandGen::Regexp

by paulski (Beadle)
on Aug 07, 2005 at 06:37 UTC ( #481626=note: print w/replies, xml ) Need Help??


in reply to Re^3: Parse::RandGen::Regexp
in thread Parse::RandGen::Regexp

OK that makes sense to me now. :-) I tried this and got it working. I'm not sure what you mean by "stored outside of code" though. Could you please clarify?

Thanks,

Paul

Replies are listed 'Best First'.
Re^5: Parse::RandGen::Regexp
by Tanktalus (Canon) on Aug 07, 2005 at 13:36 UTC

    This can mean anywhere that you need to read it from a filehandle, or get it as a return from some other function. For example, you could have it in an actual file. You could put it in a __DATA__ or __END__ block at the end of your file and read it from the *DATA filehandle. You could retrieve it using LWP from a webserver somewhere, then parse it from that. As long as it isn't contained as text inside your actual perl code where the perl compiler will see it.

    Here's an example:


    #!/usr/bin/perl -w use strict; use Parse::RandGen::Regexp; my $regexp = <DATA>; chomp $regexp; # get rid of the line termination. my $r = Parse::RandGen::Regexp->new(qr/$regexp/); my $string = $r->pick(match=>1, captures=>{}); print("\$string: $string\n"); __END__ (?smi)^STOR\s[^\n]{100}

    Here we're loading it from the __END__ section. For more info on how to use the DATA filehandle, see perldata. Otherwise, you can take the string, put it in a file, and then open/read/close that file as normal.

      Shouldn't that be
      (?smi:^STOR\s[^\n]{100})

        You made me go back to perlre again - I knew I had looked it up when giving the original answer, but you made me second guess myself. ;-) Turns out, we're both right. Without the colon, the directive applies to the end of the current block (capturing or non-capturing parenthesis). With the colon, of course, it applies only to that non-capturing block.

      Cool thanks. :-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2021-05-06 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (78 votes). Check out past polls.

    Notices?