Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

setting environment-variables

by tos (Deacon)
on Jun 12, 2003 at 14:30 UTC ( [id://265368]=perlquestion: print w/replies, xml ) Need Help??

tos has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

what's to do for assigning a perl-script-result to a Windows/DOS-box-environmentvariable ? On unix i can do it with the perl-script enclosed in backquotes. like

# export X=`perl -we 'print "foobar"'` # echo $X foobar
For the DOS-box i don't know a similar statement.

Or does there perhaps exist a special perl-way to set environment-vars in the calling (father-) process ?

thanks

p.s.: does "foobar" mean something special or is it merely a nonsense word ? I read it a dozen times in computer literature. And the guys in Spielbergs "Private Ryan" often used it, too.

Replies are listed 'Best First'.
Re: setting environment-variables
by fglock (Vicar) on Jun 12, 2003 at 14:44 UTC

    About foobar...

    update: try this:

    C:> perl -e "$a='foobar'; print 'set ZZZZ='.$a; " > foo.bat C:> foo.bat
Re: setting environment-variables
by Mr. Muskrat (Canon) on Jun 12, 2003 at 15:20 UTC

    Another option would be to store the perl script in an environment variable and call it later:

    REM MYVAR.BAT SET MYVAR=perl -we "print 'foobar'" CALL %MYVAR% PAUSE
Re: setting environment-variables (vienv)
by tye (Sage) on Jun 12, 2003 at 15:32 UTC

    I have a trick for this. I've used it in several other scripts but I just noticed that I've never uploaded vienv to PM... until now. (:

                    - tye
Re: setting environment-variables
by Anonymous Monk on Jun 12, 2003 at 15:24 UTC

    Look for the Jargon File on any search engine, and search under foo. The WWII military slang is related, but usually spelled 'fubar', as it's an acronym for <expletived> up beyond all repair.

Re: setting environment-variables
by meredith (Friar) on Jun 12, 2003 at 18:25 UTC
    In DOS/Windows, there is only one set of environment variables, not a separate environment for every process. That means that you can add the line
    $ENV{x} = $result;
    right at the end of your script and it will apply everywhere.

    If you have a Windows NT/2000/XP system, environment vars are semi-separated -- you can edit the registry to cause a global change, or you can use the line above to control the current DOS box.

    Also, foobar is a play on FUBAR, which the characters on Private Ryan used to say F00ked Up Beyond All Recognition. ;) We use it now as a nonsense word, kind of a placeholder. Do check that Jargon File reference, though, there's some interesting stuff in there!

    mhoward - at - hattmoward.org

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found