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!
In reply to how to evaluate a variable in a string? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |