If the eval succeeds, that is, no compilation errors, and
no fatal errors or dies, $@ will be *empty*. Furthermore,
what you print in an eval, you can't capture easily. By
default, it'll go to stdout. What you probably want is
something like:
#!/usr/bin/perl
use strict;
use warnings;
while (<DATA>) {
s/<# \{(.*?)\} #>/$1/eeg;
print;
}
__DATA__
<# { $a = 3; $b = 3; if ($a == $b) { "a=b"; } } #>
<# { 4*3; } #>
Which prints:
a=b
12
Note the differences:
- In the pattern, the parens are inside the braces.
- The replacement part is just $1.
- There are two /e modifiers.
- The data doesn't have prints.
Abigail