Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Can I do this ???

by rovf (Priest)
on Jan 22, 2009 at 12:56 UTC ( [id://738139]=note: print w/replies, xml ) Need Help??


in reply to Can I do this ???

i know that through child process I cant modify parents' variables. But just asking if there is a way

Fortunately not. I would feel very uneasy as a programmer if I had to worry whether my child processes secretly change my environment without me noticing. This is already pretty nasty in Windoze batch programming where this "feature" is possible.

IMHO, values should passed back to the parent in a way which is clearly visible (i.e. the caller has to ask for the values). How this is done, depends on the application being called. For instance, you might pass a filename to the application, and it writes any output parameters into the file. Or, the application uses stdout to pass data back, and you use qx() instead of system() to catch it.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: Can I do this ???
by grinder (Bishop) on Jan 22, 2009 at 14:11 UTC
    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

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-03-28 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found