Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: Can I do this ???

by grinder (Bishop)
on Jan 22, 2009 at 14:11 UTC ( #738162=note: print w/ replies, xml ) Need Help??

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


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

Comment on Re^2: Can I do this ???
Select or Download Code
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.


      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;--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 '';

      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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://738162]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2015-10-13 14:39 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (309 votes), past polls