If a perl script gets access to a string, how can the script interpret the contents of the string as perl code and execute it? My naive attempt failed:
use diagnostics; use warnings; use strict; my $a_code =<<'CODE'; sub tryme { my $foo = shift; return $foo + 2; } CODE # Intent shown here does _not_ work my $ans = eval{ $a_code; tryme( 3 ); } or die "doesn't work";
The error might be in the way in which the code in being packaged into the string $a_code, or in how $a_code is being used, or in both.
In reply to How to interpret a string as perl code and execute it? by sg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |