It'd be nice if you gave the output you were expecting ... what I got to work, without that ugly use re 'eval' workaround is:
Note how I'm using the qr operator to combine the patterns instead of just using string concatenation. This allows the Regexp objects to be treated as Regexp objects instead of forcing them to switch back and forth between string representations and regular expression objects. I suspect that this also keeps them from losing any magic - the "re 'eval'" option is probably specified in the Regexp::Common module, the regular expressions returned from there keep that, but when you stringify and re-compile them in a new scope, you need the re 'eval' option again. This way, since I'm not doing that, I don't allow anything else (that may be improperly untainted) to use the dangerous eval option while still getting the power of Abigail's Regexp::Common module (with evals).#! /usr/bin/perl -w use strict; use Regexp::Common; my $teststring= "teststring: start hello {ab}{cd} end\n"; my $balancedparens= qr/\s*$RE{balanced}{-parens=>'{ }'}/; my $pattern1= qr/($balancedparens)$balancedparens/; my $pattern2= qr/hello/; my $pattern3= qr/$pattern2$pattern1/; print "no error yet\n"; $teststring=~ s/$pattern3/hi$1/g; ## ERROR, WHY??? print $teststring;
Also, you didn't specify {-keep} anywhere, so there aren't any capturing parenthesis for $1 to show. So I added some. Not sure that's what you want to capture...
In reply to Re: Regexp::Common not so common?
by Tanktalus
in thread Regexp::Common not so common?
by iaw4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |