Just a note: I also tried $main::0 as well as $0
 (as in
 perl -e '$0 = "foo";print "$0\n";'
 perl -e '$main::0 = "foo";print "$0\n";')
after I used caller() to make sure it was in main::.

Any ideas?

JupiterHost.Net wrote:
Hello group!

Maybe a bit much for a beginners list (I looked and looked and couldn't find any specific lists) but Perhaps a guru or two will know the answer :)

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 problems 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.


#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 insigth as to why it flops and/or how to set $0 with another value in those examples?

TIA

Lee.M - JupiterHost.Net


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to