I want to (need to) start a sub-process from a perl script that checks certain environment variables. In one instance the environment variable needs to be there but empty.
$ENV{"GREETING"} = "Hello World"; # Valid
$ENV{"GREETING"} = ""; # also valid
I can set $ENV{"GREETING"} = ""; and in that perl script $ENV{"GREETING"} is empty, but in any sub-process that environment variable is not there.
Here is some example code to demonstrate. This script, env_in.pl sets up some environment variables, ZZZ_3 is empty. It then calls env_out.pl to output the environment variables, ZZZ_3 is missing from the output.
#!/usr/bin/perl
# env_in.pl
use strict;`enter code here`
use warnings;
$ENV{ZZZ_1} = "One";
$ENV{ZZZ_2} = "Two";
$ENV{ZZZ_3} = "";
$ENV{ZZZ_4} = "Four";
my (@cmd) = ("perl", "env_out.pl");
system(@cmd) == 0 or die "system @cmd failed: $?";
Here is the env_out.pl script.
#!/usr/bin/perl
use strict;
use warnings;
print ($_," = ", $ENV{$_}, "\n") for (sort keys %ENV);
I'm using ActiveState perl version v5.8.8 on a WinXP box.
I know that this DOES work in python, but I don't have a choice about the implementation language, it has to be Perl.