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:

#! /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;
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).

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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.