Why do keys with empty string values ​​for Perl% ENV not display Windows subprocesses?

I want (need) to run a subprocess from a perl script that checks for specific environment variables. In one case, the environment variable should be there, but empty.

 $ENV{"GREETING"} = "Hello World";        # Valid
 $ENV{"GREETING"} = "";                   # also valid

I can set $ ENV {"GREETING"} = ""; and that the perl script $ ENV {"GREETING"} is empty, but this environment variable is not in any subprocess.

Here is a sample code to demonstrate. This script, env_in.pl sets some environment variables, ZZZ_3 is empty. Then it calls env_out.pl to output the environment variables, ZZZ_3 is absent.

#!/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 am using ActiveState version v5.8.8 in a WinXP window.

I know this works in python, but I have no choice regarding the implementation language, it should be Perl.

+3
3

, Windows , . - , .

Perl ZZZ_3 Unix- .

+9

, , perl. windows2000 + cygwin :

$ perl --version

This is perl, v5.10.0 built for cygwin-thread-multi-64int
(with 6 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


$ perl env_in.pl | grep ZZZ
ZZZ_1 = One
ZZZ_2 = Two
ZZZ_3 =
ZZZ_4 = Four

$
0

perl, cygwin perl vista,

ZZZ_1 = One
ZZZ_2 = Two
ZZZ_4 = Four
0

Source: https://habr.com/ru/post/1715973/


All Articles