This sort of solution has been discussed before - the biggest problem is that BEGIN blocks don't quite get handled properly (as I understand it) - but this shouldn't be a problem for you, since your not writing a Perl application dependent on another Perl application. You're just writing a wrapper.
However, I wonder at the situation that prevents you from using Perl - perl2exe simply wraps the Perl program in the perl environment - effectively your carrying Perl around, so why not just get the real thing? Also, if you KNOW that you are only running ONE Perl program, why not perl2exe it instead of a writing a wrapper?
Assuming that you know the answers to the preceeding questions, then, yes this is what you are looking for. Here is a slightly more efficient variant.
Cheers,package Wrapper; #To prevent interfering with the eval'ed Program our ($code); my $prog = shift; open PROGRAM, $prog or die "Can't open $prog: $!"; { local $/; undef $/; $code = <PROGRAM> } close PROGRAM; eval $code or die "$@";
Update: Pay no attention to this crappy code, look at Juerd's cleaned up version. These aren't the droids you are looking for. Move along.
In reply to Re: eval a perl script
by erikharrison
in thread eval a perl script
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |