Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I found a better module on CPAN that does exactly what I need Parse::RandGen::Regexp.pm.

The problem I'm having now is how to get a regexp into this function. I wrote a stub progam to test.

#!/usr/bin/perl -w use strict; use Parse::RandGen::Regexp; my $regexp = "/^STOR\s[^\n]{100}/smi"; my $r = Parse::RandGen::Regexp->new($regexp); my $string = $r->pick(match=>1, captures=>{}); print("\$string: $string\n");
This throws the following error.
Unrecognized escape \s passed through at ./regexp2.pl line 6. %Error: Parse::RandGen::Regexp has an element that is not a Regexp re +ference (ref="")! at /usr/lib/perl5/site_perl/5.8.6/Parse/RandGen/Reg +exp.pm line 36 Parse::RandGen::Regexp::_newDerived('Parse::RandGen::Regexp=HASH(0 +x9dcdd88)', 'HASH(0x9e5f138)') called at /usr/lib/perl5/site_perl/5.8 +.6/Parse/RandGen/Condition.pm line 81 Parse::RandGen::Condition::new('Parse::RandGen::Regexp', '/^STORs[ +^\x{a}]{100}/smi') called at ./regexp2.pl line 7
Now I need the string in regexp format to pass to the function. I could just put the string in qr//s but in my real program I need to read the regexps from a list so they will come in scalar format.

i.e. How do I convert:

"/^STOR\s[^\n]{100}/smi";
to
qr/^STOR\s[^\n]{100}/smi
I'm not sure how to do this conversion.

Thanks,

Paul

Janitored by Arunbear - replaced pre tags with code tags, to prevent distortion of site layout and allow code extraction.


In reply to Parse::RandGen::Regexp by paulski

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2021-05-18 07:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (176 votes). Check out past polls.

    Notices?