Subject: | TZ environmental variable getting deleted. |
I read through the documents, so I'm not sure how this should be
handled. In my case my program is expecting 'TZ' to be defined after I
use the Class::Date module, but it is being deleted in Class::Date
without a suitable value being stored in it. Here is a test script that
shows the moment Class::Date is loaded the variable is cleared out. I
tested with 1.1.5 and it doesn't remove the variable.
Subject: | tz_env.pl |
#!usr/bin/perl
use strict;
use warnings;
#
# Testing using 'use'
#
my %start_env;
BEGIN {
print "\nDump ENV =============================\n";
foreach( sort keys %ENV ) { print "$_: " . $ENV{$_} . "\n"; }
%start_env = %ENV;
}
print "\nTest Start with Class::Date ==========\n";
use Class::Date;
_env_compare( \%start_env, \%ENV );
#
# Testing Using Require:
#
#my %start_env = %ENV;
#print "\nDump ENV =============================\n";
#foreach( sort keys %ENV ) { print "$_: " . $ENV{$_} . "\n"; }
#print "\nTest Start ENV =======================\n";
#_env_compare( \%start_env, \%ENV );
#print "\nTest Start with Require Class::Date ==========\n";
#require Class::Date;
#_env_compare( \%start_env, \%ENV );
######################################################################
sub _env_compare
#
#
#
######################################################################
{
my $env_one = shift;
my $env_two = shift;
my @env_one_keys = sort keys %$env_one;
my @env_two_keys = sort keys %$env_two;
my @different_list;
my @added_list;
my @removed_list;
# Prime the loop
my $current_one_key = shift @env_one_keys;
my $current_two_key = shift @env_two_keys;
while( $current_one_key && $current_two_key ) {
# Check to see if the keys match
if( $current_one_key eq $current_two_key ) {
push(@different_list, $current_one_key) unless( $env_one->{$current_one_key} eq $env_two->{$current_two_key} );
# grab new keys and continue
$current_one_key = shift @env_one_keys;
$current_two_key = shift @env_two_keys;
next;
}
# If the first key alphas before the second key, then it was removed
# in the second hash
if( $current_one_key lt $current_two_key ) {
push(@removed_list, $current_one_key);
# Grab new keys and continue
$current_one_key = shift @env_one_keys;
next;
}
# If the first key alphas after the second key, then the second
# key was added to the list
if( $current_one_key gt $current_two_key ) {
push(@added_list, $current_two_key );
# Grab new keys and continue
$current_two_key = shift @env_two_keys;
next;
}
}
# We have exausted our list at this point.
# If there are keys in the first list then they have been removed in the second list
# If there are keys in the second list then they have been added
push(@removed_list, @env_one_keys) if scalar @env_one_keys;
push(@added_list, @env_two_keys) if scalar @env_two_keys;
# Output
if( scalar @added_list ) {
my $added_string = "Added in environment:\n";
foreach( @added_list ) { $added_string .= "ADDED $_: [" . $env_two->{$_} . "]\n"; }
print $added_string;
}
if( scalar @different_list ) {
my $change_string = "Changes in environment:\n";
foreach( @different_list ) { $change_string .= "CHANGE $_: [" . $env_one->{$_} . "] => [" . $env_two->{$_} . "]\n"; }
print $change_string ;
}
if( scalar @removed_list ) {
my $removed_string = "Removed from environment:\n";
foreach( @removed_list ) { $removed_string .= "REMOVED $_: [" . $env_one->{$_} . "]\n"; }
print $removed_string ;
}
}