Subject: | File::Spec->tmpdir() autovivifies $ENV{TMPDIR} into existence on Win32 (+FIX) |
Calling File::Spec->tmpdir() on Windows polutes the environment by
creating $ENV{TMPDIR} and $ENV{TMP} with an undef value. This happens
because tmpdir() passes an array slice of these elements to a function,
which autovivifies them into existence.
C:\> perl -de0
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `perldoc perldebug' for more help.
main::(-e:1): 0
DB<1> use File::Spec
DB<2> x grep /^T/, keys %ENV
0 'TEMP'
DB<3> x File::Spec->tmpdir
0 'C:\\Temp'
DB<4> x grep /^T/, keys %ENV
0 'TEMP'
1 'TMPDIR'
2 'TMP'
DB<5> x exists $ENV{TMPDIR}
0 1
DB<6> x defined $ENV{TMPDIR}
0 ''
C:\> perl -v
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 33 registered patches, see perl -V for more detail)
Copyright 1987-2006, Larry Wall
Binary build 819 [267479] provided by ActiveState http://www.ActiveState.com
Built Aug 29 2006 12:42:41
(Running on WinXP SP2)
This is caused by line 66 of File/Spec/Win32.pm passing hash elements to
a function:
sub tmpdir {
return $tmpdir if defined $tmpdir;
$tmpdir = $_[0]->_tmpdir( @ENV{qw(TMPDIR TEMP TMP)},
'SYS:/temp',
'C:\system\temp',
'C:/temp',
'/tmp',
'/' );
I believe changing this as follows fixes the problem:
$tmpdir = $_[0]->_tmpdir( (@ENV{qw(TMPDIR TEMP TMP)})[1..3],