Forum Moderators: coopster
\\n where n is the group number. In order to escape the back reference you need to quadruple the backslash: \\\\. Since you also needed to escape the dollar sign, an extra one was needed it seems. Never run into this situation before but it certainly is an interesting one. $thisTemplate = strtr($thisTemplate, "[PRICESTRING]", $price); $thisTemplate = strtr($thisTemplate, "[PRICESTRING]", $price);
$thisTemplate = strtr($thisTemplate, array('[PRICESTRING]' => $price));
$thisTemplate = str_replace("[PRICESTRING]", $price, $thisTemplate);
an explanation that won't make my head explode?
#!/usr/bin/perl -w
$price='';
%row = (
'price' => '300.00'
);
if ($row{'price'}) {
$price = '<p>Price: $' . $row{'price'} . '</p>';
}
## For example:
$thisTemplate= qq|
<p>Blah blah</p>
[PRICE]
<p>Blah blah</p>
|;
print "<p>BEFORE:</p>\n\n $thisTemplate";
if ($thisTemplate =~ /\[PRICE\]/) {
$thisTemplate =~ s/\[PRICE\]/$price/g;
}
print "<p>AFTER:</p>\n\n $thisTemplate";