
Zhris
Enthusiast
Apr 24, 2015, 12:14 PM
Post #10 of 10
(4637 views)
|
Re: [artperl] insert image in html
[In reply to]
|
Can't Post
|
|
Hi, The regexp processes the entire html document, therefore you need to slurp your file handle into a string first. If you want to match a specific parameter number, then you must keep in mind that there is a possibility the same number may occur elsewhere. Therefore you should: - be more strict when matching by incorporating more of the surrounding syntax
s{Parameter number</b></td>\s*<td[^>]*>\Q$Tparam\E.+?</tr>\s*</table>\s*(?:<(?:br|hr)>\s*){2,2}\K}{<img src="$splitLot~$Tparam.png" alt="$Tparam Chart" />}sg; - or match all blocks then only add the img where the parameter number equals your desired parameter number.
s{Parameter number.+?(\d+)</td>.+?</tr>\s*</table>\s*(?:<(?:br|hr)>\s*){2,2}\K}{($1==$Tparam)?qq'<img src="$splitLot~$Tparam.png" alt="$Tparam Chart" />':''}sge; etc...
my $splitLot = 'blah'; my $Tparam = '177'; my $string = do { local $/ = undef; <NEWTEMP> }; $string =~ s{Parameter number</b></td>\s*<td[^>]*>\Q$Tparam\E.+?</tr>\s*</table>\s*(?:<(?:br|hr)>\s*){2,2}\K}{<img src="$splitLot~$Tparam.png" alt="$Tparam Chart" />}sg; print $string; Chris
|