Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I believe my problem is a general problem. I did a search, but found no answers.
Description:
There is a HTML file to be processed. I want to substitute a pattern with another one. There are many patterns to be processed, but I do not know how many. I came up a structure so that I can easily add a new pattern.
The structure looks like:
$file= '<A NAME="TOC124" HREF="cvs.html#SEC124">A.8 commit--Check file +s into the repository</A>'; $c->{Anchor}{from}='<A NAME="(.*?)" HREF=".*?\#(.*?)">(.*?)</A>'; $c->{Anchor}{to}='$3 |$2| *$1*'; foreach $item (keys %$c) { $from=$c->{$item}{from}; $to=$c->{$item}{to}; $file=~s/$from/$to/sg; } print "$file\n";
There is hash reference $c where I plan to add more pattern as long as necessary. The main body foreach process each of the patterns.
The expected result is:
A.8 commit--Check files into the repository |SEC124| *TOC124*
The result of my program is:
$3 |$2| *$1*
Here the problem is that $1,$2 and $3 is not evaluated. This is reasonable as I coded like this. My question is how can I make them evaluated ?
Thanks for any of your suggestions!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Danger Will Robinson! False Laziness!
by skyknight (Hermit) on Jul 30, 2003 at 17:13 UTC | |
|
Re: how to evaluate a variable in a string?
by fglock (Vicar) on Jul 30, 2003 at 17:23 UTC | |
|
Re: how to evaluate a variable in a string?
by sauoq (Abbot) on Jul 30, 2003 at 17:34 UTC | |
|
Re: how to evaluate a variable in a string?
by chunlou (Curate) on Jul 30, 2003 at 22:01 UTC | |
|
Re: how to evaluate a variable in a string?
by Kageneko (Scribe) on Jul 30, 2003 at 18:28 UTC | |
|
Re: how to evaluate a variable in a string?
by fglock (Vicar) on Jul 30, 2003 at 20:19 UTC |