in reply to Re: eval a perl script
in thread eval a perl script

open $prog, PROGRAM

I think you meant open PROGRAM, $prog.

package Wrapper; #To prevent interfering with the eval'ed Program

There's not much point in doing so if you don't switch back the package to main in the evaled code. Having $code as a global is good, but the lexical $prog will also be visible in evaluated code.

eval $code or die "$@";

You expect the code to return a true value (eval returns the last evaluated expression, just like a do-block), but that's not very common for a non-module. It's better to check $@ itself.

package Wrapper; { local $/ = undef; open PROGRAM, shift or die "Can't open $prog: $!"; $Wrapper::code = <PROGRAM>; close PROGRAM; } eval 'package main; ' . $Wrapper::code; die $@ if $@;

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.