in reply to Do people find warning for undef with string compare useful?

It is often annoying, though in some cases is does help find bugs.

I don't like introducing "if defined" checks, as they blow up the code size and make it less readable. Luckily the // operator provides a slightly more concise solution that can be use in many (but not all!) situations where you want to do string-comparison on a variable that may be undef:
Instead of...

if ($possibly_undef eq 'Hello') { ...

...write:

if ($possibly_undef//'' eq 'Hello') { ...

Or of course "no warnings 'uninitialized';" if you want to disable it completely, but I don't usually do this.

Replies are listed 'Best First'.
Re^2: Do people find warning for undef with string compare useful?
by choroba (Cardinal) on May 31, 2013 at 22:12 UTC
    Unfortunately, // has lower priority than eq. You code is equivalent to
    if ($possibly_undef) { ...

    The correct syntax is

    if (($possibly_undef // '') eq 'Hello') { ...
    Which blows up the code size and makes it less readable.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Ah yes, you're right of course.