note
sg
<p>
Thanks; string eval does work in the example. But the following bit more complex example, in which the string needs to use the "context" of the executing script, fails:
</p>
<code>
use diagnostics;
use warnings;
use strict;
my %h;
$h{ 'a' }{ 'b' } = 5;
my $b_code =<<'CODE';
sub tryme_b
{
my $foo = shift;
return ${ $foo }{ 'a' }{ 'b' };
}
CODE
my $ans = eval "$b_code; tryme_b( \%h );" or die "[$b_code] doesn't work:$@";
print "b:$ans,\n";
</code>
886415
886417