# Useage example:
my $error = run_code('/file1.pl');
print "Run code failed, err msg:\n$error" if $error;
sub run_code {
my $path = shift;
open(CODE, $path) || return "Oops: $path $!\n";
local $/;
my $code = <CODE>;
eval $code;
return $@;
}
Needs full path to code to be run.
The local $/ gives a locally undefined value to the
input record seperator $/ with the result that
we glob the whole file into $code. This saves us
from @code = <CODE>; $code= join'',@code;
The sub returns undef if it suceeds or the error
message if it fails to run the code.
Hope this helps.
tachyon
|