develooper Front page | perl.perl5.porters | Postings from April 2006

use of uninitialized value: setting ENV values

Thread Next
From:
hv
Date:
April 3, 2006 04:40
Subject:
use of uninitialized value: setting ENV values
Message ID:
200604031149.k33BnEZ01192@zen.crypt.org
I noticed in a recent make test:
ext/XS/APItest/t/call......................................Use of uninitialized value in list assignment at ./test.pl line 504.
ok

This comes from t/test.pl:
  my @keys = grep {exists $ENV{$_}} qw(CDPATH IFS ENV BASH_ENV);
  local @ENV{@keys} = ();
.. and apparently the warning occurs whenever you try to set an ENV value
to undef:
  zen% perl -we '$ENV{FOO} = undef; use Data::Dumper; print Dumper($ENV{FOO})'
  Use of uninitialized value in scalar assignment at -e line 1.
  $VAR1 = undef;
  zen% 

I thought I remembered that ENV had special magic to coerce undef to the
empty string, which would maybe explain this, but the dump shows that
isn't what's happening - and `perldoc perlvar` mentions nothing along
those lines - so is this a legitimate warning? If it is, t/test.pl should
be fixed, maybe with the patch below.

Hugo
--- t/test.pl.old	Mon Apr  3 12:47:12 2006
+++ t/test.pl	Mon Apr  3 12:47:33 2006
@@ -501,7 +501,7 @@
 	}
 
 	my @keys = grep {exists $ENV{$_}} qw(CDPATH IFS ENV BASH_ENV);
-	local @ENV{@keys} = ();
+	local @ENV{@keys} = ("") x @keys;
 	# Untaint, plus take out . and empty string:
 	$ENV{PATH} =~ /(.*)/s;
 	local $ENV{PATH} =

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About