in reply to interpolation in replacement part

Did you escape the $1 in the value? Also, you will need to double evaluate, and fix what you are evaluating:
my %patt1; my $key = "<date>([A-Z&;][a-z&;]+), ([0-9]{2}) ([0-9]{4})</date>"; my $value = "qq|<month>\$1</month>|"; $patt1{$key} = $value; $instr = '<date>Jan, 10 1997</date>'; for my $pat (keys %patt1) { if ( $instr =~ s|$pat|$patt1{$pat}|eegs ) { print "match1: $instr\n"; } }
If you're doing this repeatedly in your program, though, it would be better to compile the regexes with qr and store them in an array rather than as keys in a hash.

Replies are listed 'Best First'.
Re^2: interpolation in replacement part
by Hue-Bond (Priest) on Oct 14, 2005 at 16:30 UTC

    I was struggling with sprintfs inside the substitution. Didn't know that double quoting trick. ++.

    --
    David Serrano