in reply to regex substitution
When doing substitutions like this, /e is your friend. $text =~ s/\#\w+\#/$hash{$1}/eg; /e forces the right-hand side of the s/// to be evaluated as a Perl expression, and the result substituted for whatever the left-hand side matched. The boundary between interpolation and substitution can seem pretty hazy, but it makes a bit more sense if you imagine that the regexp is "compiled" immediately before it is executed. At that point, $1 either doesn't have a value, or holds a value from a prior regexp. Neither is what you want.
Consult perlre for full details.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: regex substitution
by coolmichael (Deacon) on Nov 05, 2001 at 10:40 UTC | |
by crazyinsomniac (Prior) on Nov 05, 2001 at 13:03 UTC |