in reply to Eval in RegEx ...
The reason is that your anonymous sub first prints the string and returns the return value of print (usually 1 for successful printing). Then you print the content in the $html variable.
I would suggest that you re-define your embedded perl in such a way that it returns a string (just remove the print command in the embedded perl. Then the embedded perl section will be replaced by the resulting string which is what you want (I assume). Code could look like this:
use strict; use warnings; use 5.0080; my $html =<<'HTML'; <div> <p>Code</p> <?perl my $string = "Hello World"; "<b>$string</b>"; ?> </div> HTML $html =~ s/\<\?perl(.*?)\?\>/(sub{$1})->()/gisee; print $html;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Eval in RegEx ...
by thakares (Acolyte) on Dec 06, 2013 at 15:49 UTC | |
by ww (Archbishop) on Dec 07, 2013 at 12:48 UTC |