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.

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 "$@";
Cheers,
Erik

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.