Does anyone know how to set an shell enviroment using perl? I have tried using the backticks, the system command, but they don't seem to be working. I found ENV{'FLEE'} = 'FLEE'; online, but I don't understand how that works. It sets your enviroment for a child process but won't change your current environment, is that right? If anyone has suggestions I am all ears.
$ENV{FLEE} = 'FLEE'; ^remember about the '$' sigil.
See perlvar(1) manpage:
http://www.perldoc.com/perl5.8.0/pod/perlvar.html#%25ENV
"The hash %ENV contains your current environment. Setting a value in ENV changes the environment for any child processes you subsequently fork() off."
"Perl programming is an *empirical* science" after all, so you can ckeck out if it changes the real environment:
#!/usr/bin/perl -wl print "Old PATH: $ENV{PATH}"; $ENV{PATH} .= ':/ABCDEF'; print "%ENV PATH: $ENV{PATH}"; $/ = "\0"; open $env, '<', "/proc/$$/environ" or die $!; while (<$env>) { print "Real PATH: $1" if /^PATH=(.*)/; } close $env;
And it doesn't. %ENV is just a normal hash, it's not tied or anything. But if it is your only way of reading your environment (and even POSIX::getenv() just returns the %ENV elements) then it doesn't really matter. I'm not quite sure if that answers your question though.
sub setEnviro { my($var1, $var2) = @_; print "INSIDE FLEE: $var1\n"; print "INSIDE FLAA: $var2\n"; #system ("FLEE=$var1"); ##ALL lines below don't seem to work. . . #system("FLAA=$var2");
This won't work, because it will change the environment of the child shell processes, which doesn't affect the environment of their parent, i.e. your program process.
#$ENV{'FLEE'} = 'FLEE'; #$ENV{'FLOO'} = 'FLAA'; `echo $FLEE`; `echo $FLAA`;
Try:
print `echo \$FLEE`; print `echo \$FLAA`;
You need to print the value returned by backticks and you need the backslach to escape the $ sigil, because otherwise perl would interpolate its $FLEE variable there. Or instead of backticks, just use system():
system 'echo $FLEE';
You don't have to escape $ in single quotes and system() doesn't capture the output of your command, so it's just printed to stdout.
-zsdc.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]