Tanktalus has asked for the wisdom of the Perl Monks concerning the following question:
I have a piece of code that does stuff randomly. Using rand (which is sufficiently random for my purposes). So that's on purpose. However, I want to be able to test certain scenarios specifically (code coverage, sorta). So I figured that since all random generation goes through a single _random function, I could just easily put a debug-hack in there that would allow me to specify the random numbers. However, I seem to get some wierd behaviour in the debug code - it's not critical, but I'm curious as to how to quash it.
The problem is given by the code below. I'm sure I could get this simpler, but I was just happy to reproduce it at all (I fought with it for about 5 minutes until I realised that, duh, the warning would only come up if I turned on warnings...).
The warning is: "Use of uninitialized value in list assignment at ./a.pl line 13."
use strict; use warnings; my $foo = '1Z1'; $ENV{Z1Z1} = '3,2,1'; for (1..5) { my $x = '?'; if ($ENV{'Z' . uc $foo}) { ($x, $ENV{'Z' . uc $foo}) = split /,/, $ENV{'Z' . uc $foo}, 2; } print $x, $/; }
Output:
3 2 Use of uninitialized value in list assignment at ./a.pl line 13. 1 ? ?
Expected/desired output: everything except the warning.
Ideally, this would be done without "no warnings" inside the assignment. If that's not possible, I'll just stick in that pragma and be done with it - I just don't like avoiding warnings or strict unless I know that it's the only way to do what I want to do, and I'm not that confident here yet.
Thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Uninitialised value in list assignment
by davidrw (Prior) on Jun 26, 2005 at 22:09 UTC | |
by Tanktalus (Canon) on Jun 26, 2005 at 22:28 UTC | |
by ysth (Canon) on Jun 26, 2005 at 23:23 UTC | |
|
Re: Uninitialised value in list assignment
by tlm (Prior) on Jun 26, 2005 at 22:04 UTC | |
|
Re: Uninitialised value in list assignment
by xdg (Monsignor) on Jun 27, 2005 at 03:43 UTC | |
|
Re: Uninitialised value in list assignment
by demerphq (Chancellor) on Jun 27, 2005 at 10:51 UTC |