anniyan has asked for the wisdom of the Perl Monks concerning the following question:
hello monks, i have come up with a problem where i could not able to search anywhere.
i have hash in which key and value are patterns.
key:<date>([A-Z&;][a-z&;]+), ([0-9]{2}) ([0-9]{4})</date> value:<month>$1</month>
when i used this above hash in the regular expression it matches in the matching but in the replacement part, the interpolation is not taking place.
So i need your help, i also tried using 'e' option modifiers twice to evaluate twice, but didnt got.
I tried with following code,
$instr = '<date>Jan, 10 1997</date>'; for my $pat (keys %patt1) { print "$pat\t$patt1{$pat}\n"; $instr =~ s|$pat|$patt1{$pat}|egs;#this is not working $instr =~ s|$pat|<month>$1</month>|gs;#this works }
For the string, <date>Jan, 10 1997</date>, when i used $1 separately in replacement part it works fine, where i get <month>Jan</month>, but when i used hash it is not getting interpolated.
Please find where i am going wrong.
Regards,
Anniyan
(CREATED in HELL by DEVIL to s|EVILS|GOODS|g in WORLD)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: interpolation in replacement part
by runrig (Abbot) on Oct 14, 2005 at 16:17 UTC | |
by Hue-Bond (Priest) on Oct 14, 2005 at 16:30 UTC | |
|
Re: interpolation in replacement part
by tirwhan (Abbot) on Oct 14, 2005 at 16:02 UTC | |
by anniyan (Monk) on Oct 14, 2005 at 16:08 UTC |