http://www.perlmonks.org?node_id=738162


in reply to Re: Can I do this ???
in thread Can I do this ???

This is already pretty nasty in Windoze batch programming where this "feature" is possible.

It is?

> type foo.cmd perl -le "print q{FOOBAR=}, $ENV{FOOBAR}" perl -e "$ENV{FOOBAR}=rand(9999)" perl -le "print q{FOOBAR=}, $ENV{FOOBAR}"

This produces

FOOBAR= FOOBAR=

Which seems to show that things are working as expected. Either that, or I suck at writing Windows batch files.

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^3: Can I do this ???
by MidLifeXis (Monsignor) on Jan 22, 2009 at 15:20 UTC

    Windows batch processing.

    @REM -------------------------------- @REM runme.cmd @echo off SET FOO=bar echo %FOO% echo Calling setter.cmd call setter.cmd echo After setter.cmd echo %FOO%
    @REM --------------------------------- @REM setter.cmd echo "I am in setter." set FOO=biz echo Setters FOO = %FOO%
    -------------------------------------- output -------------------------------------- bar Calling setter.cmd "I am in setter." Setters FOO = biz After setter.cmd biz

    The called sub command, setter.cmd, resets the environment of the caller.

    --MidLifeXis

      The reason that works is because there is no child process involved.

      The called script is processed by the calling process--in the same fashion as Perl's do script.pl;--and the changes are made to the current process' environment by the current process.

      The effect is exactly the same as:

      ## Called .pl $::ENV{ somekey } = 'somevalue'; ##calling script; do 'called.pl';

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Very true, and I should have made that point clear.

        What I meant to demonstrate is that a "typical" windows batch mode programming style (well, what I saw when I was in an environment where I had to care about those scripts) allows, even encourages, modifying the "parent" process from things that are called.

        --MidLifeXis