I posted this on clpm but have received no responses, so I wonder if it
made it to the real world.
I tried my hand at a module (see below) to help with the problem on
DOS/NT in which the Perl programmer must know the exact case spelling
of environment variables but no one else has to, i.e. $ENV{'path'},
$ENV{'Path'}, and $ENV{'PATH'} are 3 different environment variables in
Perl, but are one and the same to DOS and NT. WinEnv.pm creates a hash
that maps all case spellings of variables to the same variable, but it's
resisted all attempts to make it actually remap %ENV and do away with
having to use a different hash name.
I suspect that the answer is "you can't do that" because of %ENV's
magical and/or predefined status, but I'd like a more authoritative
source than my suspicions. If it's possible, could some more
knowledgeable person please show me the way, even if it's "study such
and such". BTW, http pointers are quite worthless to me: my net access
is behind a firewall that doesn't pass http. :-( Thanks.
----- cut -----
package WinEnv;
=head1 NAME
WinEnv - Perl module that redefines the magic %ENV hash for DOS-ish
systems so that environment variable keyword case is ignored.
=head1 DESCRIPTION
Perl maintains environment variables in a pseudo-associative-array
named %ENV. In the DOS, Windows 95, and Windows NT environments, the
system ignores environment variable case. Perl, however, doesn't, thus
"path", "Path", and "PATH" are all the same variable to the system,
but to Perl they're 3 different variables. This module eliminates case
distinctions in environment variables for the calling package when it
uses the specified hash (%WinENV by default) in place of the magic %ENV
hash. For example:
use WinEnv;
creates %WinENV for which $WinENV{'path'} is identical to $WinENV{'PATH'}
and retains the magic of %ENV.
use WinEnv 'myenv';
creates %myenv instead of %WinENV.
=head1 AUTHOR
Dave Wolfe <david_wolfe@risc.sps.mot.com>
=cut
my %envmap;
foreach (keys %ENV) {
$envmap{uc $_} = $_;
}
sub import {
my ($callpack) = caller(0);
my $pack = shift;
my @vars = @_ ? @_ : ('WinENV');
foreach (@vars) {
tie %{"${callpack}::$_"}, WinEnv, $_;
}
}
sub TIEHASH {
bless \($_[1]);
}
sub FETCH {
my $var = $envmap{uc $_[1]} || $_[1];
$ENV{$var};
}
sub STORE {
my $Var = uc $_[1];
$envmap{$Var} = $_[1] unless defined $envmap{$Var};
$ENV{$envmap{$Var}} = $_[2];
}
sub DELETE {
delete $ENV{$envmap{uc $_[1]}};
delete $envmap{uc $_[1]};
}
sub EXISTS {
exists $ENV{$envmap{uc $_[1]}};
}
sub FIRSTKEY {
my ($x) = keys %ENV;
each %ENV;
}
sub NEXTKEY {
each %ENV;
}
1;
----- cut -----
--
Dave Wolfe *Not a spokesman for Motorola* (512) 891-3246
Motorola MMTG 6501 Wm. Cannon Dr. W. OE112 Austin TX 78735-8598
made it to the real world.
I tried my hand at a module (see below) to help with the problem on
DOS/NT in which the Perl programmer must know the exact case spelling
of environment variables but no one else has to, i.e. $ENV{'path'},
$ENV{'Path'}, and $ENV{'PATH'} are 3 different environment variables in
Perl, but are one and the same to DOS and NT. WinEnv.pm creates a hash
that maps all case spellings of variables to the same variable, but it's
resisted all attempts to make it actually remap %ENV and do away with
having to use a different hash name.
I suspect that the answer is "you can't do that" because of %ENV's
magical and/or predefined status, but I'd like a more authoritative
source than my suspicions. If it's possible, could some more
knowledgeable person please show me the way, even if it's "study such
and such". BTW, http pointers are quite worthless to me: my net access
is behind a firewall that doesn't pass http. :-( Thanks.
----- cut -----
package WinEnv;
=head1 NAME
WinEnv - Perl module that redefines the magic %ENV hash for DOS-ish
systems so that environment variable keyword case is ignored.
=head1 DESCRIPTION
Perl maintains environment variables in a pseudo-associative-array
named %ENV. In the DOS, Windows 95, and Windows NT environments, the
system ignores environment variable case. Perl, however, doesn't, thus
"path", "Path", and "PATH" are all the same variable to the system,
but to Perl they're 3 different variables. This module eliminates case
distinctions in environment variables for the calling package when it
uses the specified hash (%WinENV by default) in place of the magic %ENV
hash. For example:
use WinEnv;
creates %WinENV for which $WinENV{'path'} is identical to $WinENV{'PATH'}
and retains the magic of %ENV.
use WinEnv 'myenv';
creates %myenv instead of %WinENV.
=head1 AUTHOR
Dave Wolfe <david_wolfe@risc.sps.mot.com>
=cut
my %envmap;
foreach (keys %ENV) {
$envmap{uc $_} = $_;
}
sub import {
my ($callpack) = caller(0);
my $pack = shift;
my @vars = @_ ? @_ : ('WinENV');
foreach (@vars) {
tie %{"${callpack}::$_"}, WinEnv, $_;
}
}
sub TIEHASH {
bless \($_[1]);
}
sub FETCH {
my $var = $envmap{uc $_[1]} || $_[1];
$ENV{$var};
}
sub STORE {
my $Var = uc $_[1];
$envmap{$Var} = $_[1] unless defined $envmap{$Var};
$ENV{$envmap{$Var}} = $_[2];
}
sub DELETE {
delete $ENV{$envmap{uc $_[1]}};
delete $envmap{uc $_[1]};
}
sub EXISTS {
exists $ENV{$envmap{uc $_[1]}};
}
sub FIRSTKEY {
my ($x) = keys %ENV;
each %ENV;
}
sub NEXTKEY {
each %ENV;
}
1;
----- cut -----
--
Dave Wolfe *Not a spokesman for Motorola* (512) 891-3246
Motorola MMTG 6501 Wm. Cannon Dr. W. OE112 Austin TX 78735-8598