Surely Perl knows this, since it may need to return there when the called script finishes.

For do, require, eval and sub calls, everything happens within Perl, so yes.

For the others, no. When Perl exits, the process simply stops doing anything. It doesn't control to the process that spawned Perl since it never stopped. Creating a child process is like creating a child person. You end up with two entities that operate independently. You can't return because the parent moved on.

How do I find the name of the script which called my current script, in Perl?

For calls within the Perl interpreter, (e.g. for do and require), Perl provides a wealth of information via caller.

For information about the parent process, you'll need an OS-dependent solution. There may be platform-independent and/or platform dependent modules that does this, but I haven't encountered them (or looked for them). Someone else will have to answer this part of the question.


In reply to Re: Find name of calling script? by ikegami
in thread Find name of calling script? by tel2

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.