Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^5: Parse::RandGen::Regexp

by Tanktalus (Canon)
on Aug 07, 2005 at 13:36 UTC ( [id://481673]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^6: Parse::RandGen::Regexp
by ikegami (Patriarch) on Aug 08, 2005 at 12:37 UTC
    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.

Re^6: Parse::RandGen::Regexp
by paulski (Beadle) on Aug 08, 2005 at 06:30 UTC
    Cool thanks. :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-29 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found