Hello Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.