Nevertheless, I don't often use uninitialized values as actual values

You never optional fields in your data structures? You never use optional parameters? You never use output parameters (e.g. open)?

I use undefined values every 5 lines of code, I bet. Yes, you're telling me that one in five of my lines of code should warn.

And I don't consider "my $x = 123;" to use undef at all: in this context

That may be, but it is. You're doing sassign($x, 123) and $x is undefined, and you indicated you want all undefined operands to warn.

since it's defined to deal with undef, certainly it should not throw a warning with undef!

And of course, so are truth tests.

Thank god. I thought you wanted us to use

if (exists($h{x} && defined($h{x}) && $h{x})

instead of

if ($h{x})

I would like warnings whenever I try to access the value of undef.

Except you said you don't want those that expect undef as an argument to warn, so I don't know of a single thing you think should start warning that doesn't already.

Update: I just thought one. You surely want length($undef) to warn. That used to be the case, but that got fixed.

This way, the common check

if (defined($s) && length($s))

can be written as

if (length($s))

And it doesn't hurt since you still get a warning (instead of two) if you use length wrong.

my $length = length($undef); # Used to warn here. print $length; # Still warn here. my $length = length($undef); # Used to warn here. for (1..$length) # Still warn here. my $length = length($undef); # Used to warn here. pack 'N', $length # Still warn here. ...

As far as I can tell, the only change you want to have done is to remove a small but awesome improvement to Perl.


In reply to Re^5: When DOESN'T "Use of uninitialized value" show up? by ikegami
in thread When DOESN'T "Use of uninitialized value" show up? by Tim McDaniel

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.