Hello group!

I hope I have the right list (I looked and looked and couldn't
find any specific lists) if not just point me int he right direction

I've been playing with embedding Perl code into a C program that can
interpret the code.
 (as per http://www-h.eng.cam.ac.uk/help/mjg17/perldoc/pod/perlembed.html
http://search.cpan.org/~krishpl/pod2texi-0.1/perlembed.pod
http://search.cpan.org/~nwclark/perl-5.8.4/pod/perlembed.pod
)

This example works great: (I realize @ARGV is clobbered but that isn't
the point right now, its for another sleepless night ;p)

  (compiled with: gcc -o compiled_version simple.c `perl
-MExtUtils::Embed -e ccopts -e ldopts`)

#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

main (int argc, char **argv, char **env)
{
        char *embedding[] = { "", "-e", "0" };
        my_perl = perl_alloc();
        perl_construct(my_perl);
        perl_parse(my_perl, NULL, 3, embedding, NULL);
        perl_run(my_perl);
        perl_eval_pv("print qq(Hello World - I come from the planet
C and i am -$0-\n);", TRUE);
        perl_destruct(my_perl);
        perl_free(my_perl);
}

But the problem I've found is:
 1) $0 is -e since we're not making just another copy of perl but
running internal code internally by specifying -e
   1.a) If I change -e to the file name (IE C's argv[0]), it errors out
because it tries to open the file to execute as perl code like doing
perl file.pl
   1.b) If i try to set $0 myself I get a bus error (Try it :add $0 =
'actual_file.name';) Which, while a bad idea generally, still works with
regular Perl.
   1.c) The same applies if I use the entire package name $main::0
instead of $0 after i use caller(0 to verify we're still in main...

#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

main (int argc, char **argv, char **env)
{
        char *embedding[] = { "", "-e", "0" };
        my_perl = perl_alloc();
        perl_construct(my_perl);
        perl_parse(my_perl, NULL, 3, embedding, NULL);
        perl_run(my_perl);
        perl_eval_pv("print qq(Zero is -$0-\n);$0 =
'realnamefromargv[0]here';print qq(Zero is -$0-\n);", TRUE);
        perl_destruct(my_perl);
        perl_free(my_perl);
}

So does anyone have any insight as to why it flops and/or how to set $0
with another value in those examples?
(I can get argv[0] into the Perl no prob, I just can't set $0 )

TIA

Lee.M - JupiterHost.Net




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to