The problem you're running into is that environment variables that are set only apply to the process where they're set and any subprocesses. In this case, system creates a child process, the environment variables are set in that child process, then the child process exits. In the shell scripts, they're included with the "dot" operator or "source" command, which runs those scripts as if they were a part of the current script.

Unfortunately there's no similarly easy mechanism in Perl, because the scripts are written in the shell scripting language, Perl doesn't include an interpreter for that language. Instead, you have to parse them yourself, as the example linked to above does; essentially it implements a very small and simplistic shell interpreter for the small subset of the shell language you're interested in (setting environment variables).


In reply to Re: set environment for parent process by sgifford
in thread set environment for parent process by Ronnie

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.