- PUBLIC VARIABLES
- BUGS AND IRRITATIONS
Perl - embed a perl interpreter in a Perl program
use Perl; my $p = Perl->new; print $p->eval(q/"Hello" . " " . "world" . "\n"/);
Perl object represents a separate perl interpreter that you can manipulate from within Perl. This allows you to run other scripts without affecting your current interpreter, and then examine the results.
This creates and initialises a new perl interpreter, and returns an object through which you can manipulate it. Paramaters are
- ARGV => ARRAYREF
This sets the arguments for the perl interpreter, as passed to "perl_parse" in perlembed. An initial argv of
"perl"will be added automatically, so don't try and include one. If no arguments are passed, a single argument of
-e0will be used.
- USE => ARRAYREF
This will add appropriate
-Marguments to the argv of the new interpreter. These will be added before any args given with
- INC [=> ARRAYREF]
This will pass appropriate
-Iarguments to the interpreter, before those from either
USE. If the
ARRAYREFis not specified, it will pass in the current
@INC, omitting entries that are references.
If the creation fails, it returns
This invokes "perl_run" in perlembed on the interpreter, which will run the program given on the command line in
Perl->new, if any. END blocks will be run at the end of this, so if you install any you must make sure to call this.
evals EXPR in the other interpreter, and returns the string value of the result.
This returns the result of evaluating EXPR in the other interpreter. Results are passed back using Data::Dumper, and if anything is returned that cannot be frozen an exception will be thrown. Any exceptions thrown will be caught in
$@ and undef returned, as with normal eval.
The EXPR will be evaluated in the same context (list, scalar, void) as eval is called in.
This will croak if Data::Dumper cannot be required in the sub-interpreter.
Note that you may wish to use _eval instead for more control over the other interpreter.
This will construct an expression that evaluates to a deep clone of EXPR, suitable for interpolating into a string to pass to
EXPR will be evaluated in scalar context.
This is a tied hash which returns the result of calling Perl::make_expr on the given key: it makes it easier to interpolate into strings.
This is used to determine whether or not Data::Dumper should attempt to deparse CODE refs. Note that you need a new enough version of Data::Dumper for this to have any effect.
If this variable is set in the environment, copious amount of debugging info will be produced on STDERR. This is almost certainly of no use to anyone but me.
Anything that can't be Dumped, in particular filehandles, can't be passed between interpreters.
There are crashes in t/6threads.t with both AS Perl and MinGW perl. I don't fully understand why they occur, but I suspect a bug in perl.
Gurusamy Sarathy <email@example.com>
Modified and updated for 5.8 by Ben Morrow <firstname.lastname@example.org>
This program is distributed under the same terms as perl itself.