A couple of answers. Note: I haven't really read all your code, but it seems to be a bit too complicated for what you're trying to achieve. It's a bit hard to tell what you're trying to achieve exactly, though. :-)

1. You can insert any perl code into the currently running program using "eval STRING". Like this:

my $code = 'print "stuff\n"'; # in your example this would be read fr +om STDIN. eval $code; # <- eval STRING, not eval { BLOCK } $@ and warn "Found an error: $@";
Note that truly malicious code can leave your main program in an incomplete state or even force your program to quit. See also Safe and eval.

Perl doesn't really compile into bytecode, or at least not like Java does. You can currently mess with the compiled code in the interpreter, but it gets complicated fast and there are few reasons to do it.

2. The compiled code normally stays in memory. If you really want to you can save the interpreter state/bytecode to a file but that's not well supported and all my personal attempts to use it for anything have failed miserably. See perlcc.

If you want some sort of "binary distribution" (i.e. one executable file instead of perl interpreter and many modules/scripts) take a look at PAR.

update: fixed link to PAR.


In reply to Re: About Embedding Perl Codes on a Current Running Program by Joost
in thread About Embedding Perl Codes on a Current Running Program by PerlPhi

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.