Hi, Please, check my comments below:
On Wed, Dec 26, 2012 at 4:10 PM, <gator...@yahoo.de> wrote: > Hi, > > I would like to store regular expressions and substitution strings in > a hash variable. If a given string matches any of the stored patterns, > the corresponding substitution should be applied. What originally looked > trivial turned out to be quite a challenge, particularly if the > substitution string contains references to capture buffers. > > Here's a minimal example: > > my $rx=qr/^aaaa_(.*)/; > my $r='a_$1'; > I would rather use: my $r = 'a_'; my $s="aaaa_bla_fasel_blub"; > if ($s=~ /$rx/) { # pattern matches, apply substitution if you can > # hardcoded, it's trivial: > # $s =~ s/$rx/a_$1/; > # but how to interpolate the capture buffer? Not like this: > # eval '$s="$r"'; > # eval { $s=$r }; > # $s =~ s/$rx/$r/e; > } > if ( $s =~ m/$rx/ ) { $s =~ s/$rx/$r$1/; } print $s, $/; # prints a_bla_fasel_blub > > Can anybody think of a straightforward way to do this? > > Regards, > Peter > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- Tim