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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |