Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

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


Comment on Re^2: Can I do this ???
Select or Download Code
Re^3: Can I do this ???
by MidLifeXis (Prior) 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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-09-20 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls