The standard Unix semantics is this:  a child process inherits the
environment from its parent.  Therefore if you (export and) set an
environment variable in a process and then run a script, it will see
that environment variable.

Furthermore, _Programming Perl, 3rd ed_ by Wall et all says this about
%ENV on p. 661:
Setting a value in %ENV changes the environment for both your process
and child processes launched after the assignment.

I tried this test program and it worked:

$ENV{MCGILLICUDY} = 'corncob pipe';
system( qq{echo \$MCGILLICUDY} );

-Will


> -----Original Message-----
> From: Scott Smith [mailto:[EMAIL PROTECTED]
> Sent: Friday 19 January 2007 14:53
> To: Reidy, Ron
> Cc: Oscar Gomez; dbi-users@perl.org
> Subject: Re: environment variable
>
>
> Reidy, Ron wrote:
> > Oscar,
> >
> > Short answer - you cannot (sort of).  This is because your
> shell script
> > will execute in a sub shell of your perl program.
> >
> > However, you can do something like this:
> >
> > # untested
> > system("export VAR=val; /path/to/your/shell/script.sh");
>
> The shell also takes a series of zero or more key-value pairs
> at the start of any command:
>
> system("VAR=val VAR2=anotherval /path/to/any/program");
>
> This has the same effect as exporting when you're doing it
> with Perl's system call, but it's good to
> keep in mind when you don't want to keep the variable setting
> or override in your general shell
> session. i.e.
>
> LD_PRELOAD=/usr/lib/special_old_library.so /usr/bin/oldprogram
>
> Scott Smith
> Genome Sequencing Center
>



     - - - - - Appended by Scientific Atlanta, a Cisco company - - - - - 
This e-mail and any attachments may contain information which is confidential,
proprietary, privileged or otherwise protected by law. The information is solely
intended for the named addressee (or a person responsible for delivering it to
the addressee). If you are not the intended recipient of this message, you are
not authorized to read, print, retain, copy or disseminate this message or any
part of it. If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete it from your computer.

Reply via email to