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

Hi all,

I am writing a script in perl. I am trying to set a new local var in the script.

The thing is after the script ends the var is no longer set.

I tried doing this using an external shell script that sets the var but still it didn't worked for me.

The Perl script is:
#/usr/bin/perl -w print `. changeShell.sh "/usr/bin"`;
The shell script is:
#!/usr/bin/bash CLASS_BLB=$1 export CLASS_BLB
After invoking the perl script the var CLASS_BLB is not set.. Any idea?? Thanks!

Replies are listed 'Best First'.
Re: Trying to set a shell var from a perl script
by JavaFan (Canon) on Aug 18, 2010 at 12:27 UTC
    The variable is set. The problem you are facing is that you are setting the variable in a different process.

    In Unix, if process A calls process B, process B cannot set of modify the environment variables of A. This is generally considered to be a feature (as allowing B to modify the environment of A would make A vulnerable to all kinds of security problems).

    AFAIK, this is true on Windows as well. I vaguely remember the faq mentioning it would be possible under VMS, but if it ever did, it hasn't mentioned this for at least a decade.

Re: Trying to set a shell var from a perl script
by Corion (Patriarch) on Aug 18, 2010 at 12:03 UTC

    You cannot set a shell variable from a Perl script.

Re: Trying to set a shell var from a perl script
by choroba (Cardinal) on Aug 19, 2010 at 16:03 UTC