paulski has asked for the wisdom of the Perl Monks concerning the following question:
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.
This throws the following error.#!/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");
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.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
i.e. How do I convert:
to"/^STOR\s[^\n]{100}/smi";
I'm not sure how to do this conversion.qr/^STOR\s[^\n]{100}/smi
Thanks,
Paul
Janitored by Arunbear - replaced pre tags with code tags, to prevent distortion of site layout and allow code extraction.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parse::RandGen::Regexp
by Tanktalus (Canon) on Aug 06, 2005 at 16:46 UTC | |
by paulski (Beadle) on Aug 07, 2005 at 03:30 UTC | |
by Tanktalus (Canon) on Aug 07, 2005 at 03:42 UTC | |
by paulski (Beadle) on Aug 07, 2005 at 06:37 UTC | |
by Tanktalus (Canon) on Aug 07, 2005 at 13:36 UTC | |
| |
Re: Parse::RandGen::Regexp
by CountZero (Bishop) on Aug 06, 2005 at 16:11 UTC | |
Re: Parse::RandGen::Regexp
by ikegami (Patriarch) on Aug 06, 2005 at 16:11 UTC | |
by paulski (Beadle) on Aug 07, 2005 at 03:21 UTC | |
by ikegami (Patriarch) on Aug 07, 2005 at 07:09 UTC | |
by paulski (Beadle) on Aug 08, 2005 at 06:31 UTC |
Back to
Seekers of Perl Wisdom