Oops , Mine was a wild guess and I am sorry for that. The below test was successful in setting environment variable ...
---------------- clip-------- #!/usr/bin/perl use Env; print "Before -->"; print %ENV; print "\n"; $ENV{TEMP}="xxx"; print "After --> \n"; print %ENV; print "\n"; system("echo $TEMP"); -----------------clip---------- Br Arjun Deserve before you desire -----Original Message----- From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 19, 2005 9:20 AM To: Mallik Arjun (WT01 - TELECOM SOLUTIONS) Cc: [EMAIL PROTECTED]; beginners@perl.org Subject: Re: set environment variables "Because it's up-side down. Why is that? It makes replies harder to read. Why not? Please don't top-post." - Sherm Pendley, Mac OS X list [EMAIL PROTECTED] wrote: > Hi , > Try below. > If you are using csh for executing perl script ------> system("setenv > TEMPHOME /tmp "); > If your using bash for executing perl script ---------> $TEMPHOME = > "/tmp"; > > system("export $TEMPHOME"); > > > Arjun > > Deserve before you desire > > Did you test it? The problem with this approach is that you are setting the environment in the subshell of 'system', but as soon as you have set that variable your 'system' returns, the subshell process is destroyed and the "new" environment has disappeared again. You must set the environment once in the same subshell as the command you wish to run in that shell. Generally you have the way the other posters have shown, by setting the environment in Perl and then allowing the subshell to inherit that environment, or by passing multiple commands in a single shell call, generally by separating them with a semi-colon. It is because each call to 'system' creates its own exclusive subshell that the more obvious, system("export VAR=value"); system("some_other_command"); Does not work. http://danconia.org > > > > > > -----Original Message----- > From: Nishi Prafull [mailto:[EMAIL PROTECTED] > Sent: Tuesday, July 19, 2005 1:49 AM > To: Perl Beginners List > Subject: set environment variables > > > Hi: > > I need to run a script noted by $cmd1 from within perl but before that > i need to set the environment variable. how can i do it? I tried my > $TEMPHOME = "/tmp"; system($cmd1); > > But the script still complains the $TEMPHOME is not set. Thanks. > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > > > > Confidentiality Notice > > The information contained in this electronic message and any > attachments to this message are intended for the exclusive use of the > addressee(s) and may contain confidential or privileged information. > If you are not the intended recipient, please notify the sender at > Wipro or [EMAIL PROTECTED] immediately and destroy all copies of > this message and any attachments. > Confidentiality Notice The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender at Wipro or [EMAIL PROTECTED] immediately and destroy all copies of this message and any attachments. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>