gweekly has asked for the wisdom of the Perl Monks concerning the following question:
# -*- perl -*-
# badperl 19-Jan-2017 12:27 gweekly
# Run on Windows
# for our 5.20.2:
# >...\latest520\bin\perl i:\bin\badperl
# for 5.8.8:
# >...\stable\bin\perl i:\bin\badperl
use strict;
use warnings;
use XML::LibXML;
# Pre-condition
die "Please re-run having removed SAM from the environment\n"
if grep { /^ SAM $ /xmsi} keys %ENV;
# Set-up
my ( $node )
= XML::LibXML->new->parse_string(q{<xml><xyz name='SAM'/></xml>})
->documentElement
->find('child::*')
->get_nodelist;
my ( $attr ) = $node->attributes; # eg: name=name,value=SAM
my $name = $attr->value;
my $fixed = substr "X$name", 1; # Should be the same
# Confirm $name and $fixed appear to be as expected
print "name is '$name', fixed is '$fixed'\n";
die 'name is not SAM' if $name ne 'SAM';
die 'fixed is not SAM' if $fixed ne 'SAM';
die 'fixed is not name' if $fixed ne $name;
delete $ENV{$name}; # Here badness happens
print defined $ENV{SAM} ? "WRONG: ENV{SAM} is defined\n"
: "OKAY: ENV{SAM} is not defined\n";
print defined $ENV{$name} ? "WRONG: ENV{\$name} is defined\n"
: "OKAY: ENV{\$name} is not defined\n";
print exists $ENV{SAM} ? "WRONG: ENV{SAM} exists\n"
: "OKAY: ENV{SAM} does not exist\n";
print exists $ENV{$name} ? "WRONG: ENV{\$name} exists\n"
: "OKAY: ENV{\$name} does not exist\n";
if ( grep {$_ eq 'SAM'} keys %ENV ) {
print "WRONG: ENV has the key 'SAM'\n";
my $exists = exists $ENV{$fixed};
print "Note: \$ENV{\$fixed} does " . ($exists?'':'NOT ') . "exist\n";
}
__END__
# 5.8.8
C:\Users\gweekly>...\stable\bin\perl i:\bin\badperl
name is 'SAM', fixed is 'SAM'
OKAY: ENV{SAM} is not defined
OKAY: ENV{$name} is not defined
OKAY: ENV{SAM} does not exist
OKAY: ENV{$name} does not exist
C:\Users\gweekly>c:\ActivePerl-5.14.2\bin\perl i:\bin\badperl
name is 'SAM', fixed is 'SAM'
OKAY: ENV{SAM} is not defined
OKAY: ENV{$name} is not defined
OKAY: ENV{SAM} does not exist
OKAY: ENV{$name} does not exist
C:\Users\gweekly>c:\ActivePerl5.16.3\bin\perl i:\bin\badperl
name is 'SAM', fixed is 'SAM'
OKAY: ENV{SAM} is not defined
OKAY: ENV{$name} is not defined
OKAY: ENV{SAM} does not exist
OKAY: ENV{$name} does not exist
C:\Users\gweekly>c:\ActivePerl5.18.1\bin\perl i:\bin\badperl
name is 'SAM', fixed is 'SAM'
OKAY: ENV{SAM} is not defined
OKAY: ENV{$name} is not defined
OKAY: ENV{SAM} does not exist
WRONG: ENV{$name} exists
WRONG: ENV has the key 'SAM'
Note: $ENV{$fixed} does NOT exist
C:\Users\gweekly>...\latest520\bin\perl i:\bin\badperl
name is 'SAM', fixed is 'SAM'
OKAY: ENV{SAM} is not defined
OKAY: ENV{$name} is not defined
OKAY: ENV{SAM} does not exist
WRONG: ENV{$name} exists
WRONG: ENV has the key 'SAM'
Note: $ENV{$fixed} does NOT exist
# Active-v5.24.1
C:\Users\gweekly>perl i:\bin\badperl
name is 'SAM', fixed is 'SAM'
OKAY: ENV{SAM} is not defined
OKAY: ENV{$name} is not defined
OKAY: ENV{SAM} does not exist
WRONG: ENV{$name} exists
WRONG: ENV has the key 'SAM'
Note: $ENV{$fixed} does NOT exist
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LibXML and %ENV in 5.18 on Windows
by poj (Abbot) on Jan 20, 2017 at 20:50 UTC | |
by gweekly (Novice) on Jan 23, 2017 at 17:39 UTC | |
by gweekly (Novice) on Jan 23, 2017 at 14:25 UTC | |
by poj (Abbot) on Jan 23, 2017 at 15:22 UTC | |
by gweekly (Novice) on Jan 24, 2017 at 16:07 UTC | |
|
Re: LibXML and %ENV in 5.18 on Windows
by gweekly (Novice) on Jan 20, 2017 at 17:36 UTC | |
|
Re: LibXML and %ENV in 5.18 on Windows
by stevieb (Canon) on Jan 20, 2017 at 17:48 UTC | |
by gweekly (Novice) on Jan 20, 2017 at 18:06 UTC | |
by stevieb (Canon) on Jan 20, 2017 at 18:25 UTC | |
|
Re: LibXML and %ENV in 5.18 on Windows
by gweekly (Novice) on Jan 25, 2017 at 22:08 UTC |