I'm using SVGs as report templates for an program I'm working on. In order to make the system as simple as possible for the designer, I'm using simple string substitution on the SVG to replace field names with HTML::Template tags. This works great for the basic stuff. One thing I need to be able to do, though, is identify specific embeded JPEG images in the SVG and replace them with HTML::Template tags as well. I'm trying to do this using a regular expression to match the correct base64 image data, but it isn't working. Here's what I've tried:
my $base64_image = encode_base64($buf);
my $text = do { local( @ARGV, $/ ) = "test_template.svg" ; <> } ;
$text =~ s/##([a-zA-Z0-9_\.]+)##/<TMPL_VAR name="$1">/g;
my $photo_count = 1;
while ($text =~ s/\Q$base64_image/<TMPL_VAR name="photo_$photo_count">
+/s){
$photo_count++;
}
I've verified that $base64_image is the same as what is found in the SVG. What am I doing wrong? Incorrect modifiers on the regular expression?
Thanks in advance.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.