Sure, you can store perl code as a string in a file or a database. Here is an example of how to turn it into a sub.
$code = "print 'Hello World.'"; # This may have come for your DB $sub = eval "sub { $code }"; # use eval and string interpolation to co +nvert it into an anon. sub $sub->(); # Execute the sub; # To pass arguments to the sub, do this: $sub->($a1, $a2); #etc # You can capture the return value too $ret = $sub->();
Update: I almost forgot to warn you: be very careful with who has access to the string version of the perl code. Obviously, if that data came from an untrusted source, they could destroy your system!
Ted Young
($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)In reply to Re: Creating subroutines on the fly
by TedYoung
in thread Creating subroutines on the fly
by pander
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |