But undef isn't zero. Zero is a defined value.

In C, #define NULL ((void*)0). In C++, #define NULL (0). In Perl, zero is a number and undef is a completely different scalar concept.

There are many levels of truth in Perl, unlike those other languages. There's non-zero. There's non-empty. There's defined. And the opposite of all of these is undef. (There's even the concept of not existing, which is even less than undef.)

You can have a hash key of '0' and a different hash key of '', even though both are evaluated as "false" when used in a condition. However, you can't have a hash key of undef. Why? Because undef isn't a string, just like it isn't a number.

In short, you will have to change your code to accept these two different values. Or say no warnings; in blocks where you want Perl to read your mind without complaining. But don't expect the computer to read your mind so well as to assume you want '0' when you say undef.

--
[ e d @ h a l l e y . c c ]


In reply to Re: Stringifying undefs by halley
in thread Stringifying undefs by BUU

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.