in reply to Uninitialised value in list assignment

Well, it's warning cause there's an undef on the third split :)
($x, $ENV{Z1Z1}) = ( '3', '2,1' ); # first time ($x, $ENV{Z1Z1}) = ( '2', '1' ); # second time ($x, $ENV{Z1Z1}) = ( '1', undef ); # third time
To avoid it, you can explicitly get and check the split() results:
my @arr = split /,/, $ENV{'Z' . uc $foo}, 2; $x = shift @arr; $ENV{'Z' . uc $foo} = scalar @arr ? $arr[0] : ''; # set to empty s +tring if nothing available

Replies are listed 'Best First'.
Re^2: Uninitialised value in list assignment
by Tanktalus (Canon) on Jun 26, 2005 at 22:28 UTC

    Yes, but I guess what has me confused is why: perl -we '$x=1;$y=1;($x,$y)=("1",undef)' doesn't give any warning, while: perl -we '$x=1;($x,$ENV{y})=("1",undef)' does. Upon which I think I just found my solution... just use a temp variable for the two, and the warning goes away... although it seems strange that this warning is only for the list case, and that it only comes up when %ENV is being assigned to. If I use %E rather than %ENV, the error doesn't come up, either. Wierd.

    Update: Duh, it's because I'm assigning undef to an environment variable Sigh. That warning was a bit too wierd for me to figure out. Chalk that one up to experience - I now have some more. Sorry for wasting your time - hopefully you can learn from this public "D'oh!" moment.

      Yup; normally assignment doesn't trigger any warnings, but if there's magic attached to the assignee, it may. Here's another example:
      $ perl -we'$|="abc"' Argument "abc" isn't numeric in scalar assignment at -e line 1.