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,


In reply to Uninitialised value in list assignment by Tanktalus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.