[When I read "I have a script that runs a set of commands", I thought you meant a shell script that executed the Perl program showed. A more careful re-reading show this is probably not what you meant. This answer probably won't help you.]


There's no generic way of making another process do something.

If the Perl program needs to cause Perl's parent process to do something, you will need devise a way to communicate with it if there isn't already one, and ask it to perform the action using that method of communication. How this should be done will depend on the parent process and what exactly you want to do.

For example, if the parent is expected to be sh, you could have the program output sh commands to stdout and have the shell capture and execute them.

x=123 printf '%s\n' "$x" # 123 eval "$( perl -Mv5.14 -e'say "x=456"' )" printf '%s\n' "$x" # 456

In reply to Re: Run system command in same context of the script itself by ikegami
in thread Run system command in same context of the script itself by igorle

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.