I've found (barely) enough documentation to be able to use perl_parse from a C program (along with all the other necessary "embed" code), but nothing to give great details about what happens between the call to perl_parse and the Perl code accessing a value for $0.

Without going into too much detail (yet) -- briefly -- I'm looking at being able to have a Perl script which can be run in one of two ways: directly, or embedded from another C program. In the C program, I'm using the normal embedding calls and calling perl_parse with the name of the perl script and properly shifted argc/argv values passed to the C program. As expected by default, $0 is being set to the leaf name of the script loaded by perl_parse.

I'm wondering if there is any way to have $0 be set to some other value than the perl script file name itself under the condition that it is parsed/loaded by my C program. (I.e. I want $0 to have a different value when loaded from the embedding code than it has when run directly.) Oh, and BTW, the value of $0 just happens to be used in BEGIN blocks so it needs to be set during the compile phase, not after the perl_parse call returns (i.e. so I can't just set it using sv_setpv_mg (or something similar) later on.

I suppose it's entirely possible that perl_parse allows no way to have a different value set for $0, but I thought I'd better ask. And see if anyone knows of other documentation with such details than what searches at many search engines have been able to find.

Thanks!


In reply to using perl_parse and setting $0 by dbmears

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.