my @variables = $_ =~ m/<\?--(\S+?)-->/g;

One really minor nitpick: $_ is the topicalizer and as such it is implicit in many operations, wich makes for terse syntax. So one either wants a fully qualified variable name like $line and thus

my @variables = $line =~ /<\?--(\S+?)-->/g;

or

my @variables = /<\?--(\S+?)-->/g;
for my $variable ( @variables ){ # replace the tag with the value of the variable # if there is one. s/<\?--$variable-->/$$variable/g if $$variable; }

One major nitpick: I would've ++'ed your node for mentioning another WTDI, complete of interesting considerations, but I --'ed it since you're unnecessarily using symrefs whereas we warn newbies all the time about the risk of doing so. It just amounts to using the symbol table as a generic hash, which is a good reason to use a specific one instead, e.g. %value. Failing to do so you should be prepared to cope with some corner cases: what if he as a <?--0--> or <?--$--> tag? Well, unprobable enough, granted, but even without that putting all values together in a separate structure is saner. The OP is clearly a newbie, so he may read your example as advocating symrefs and take them as a programming habit, that first or later may bite him in the neck.

Also, I would throw a defined in there for one may well want to replace say <?--cost--> with 0.


In reply to Re^2: Performance Question by blazar
in thread Performance Question 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.