in reply to Re^2: Do people find warning for undef with string compare useful?
in thread Do people find warning for undef with string compare useful?

{ local $^W; # expression or statement using eq or ne (or lt or le or gt or ge + or cmp) here }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^3: Do people find warning for undef with string compare useful?
  • Download Code

Replies are listed 'Best First'.
Re^4: Do people find warning for undef with string compare useful?
by perl-diddler (Chaplain) on Jun 01, 2013 at 13:17 UTC
    I think you missed the world "*only*" for the eq/ne operators.

    I'm looking more for a scalpel, not TNT. ;-)

      I think you missed the world "*only*"

      I didn't miss it; but neither did I ever claim to be able to do "only". What I showed is the way I shut warnings up on those rare occasions when I need to.

      I get your point about TNT, but as I only ever shut them at the smallest scope possible, and then only temporarily until I've decided on a better solution.

      I think that most of the complaints against these warnings come because those people approach the silencing of them from the wrong direction.

      That is, they attempt to silence them at the point where the warning occurs; using stuff like:$maybeUndef // '' or whatever. That rapidly gets hard work and messy where the variable is used multiple times; or is interpolated into string and regex etc.

      IMO the correct way to tackle the warnings is to do so at the point where they might be set to undef.

      Initialising them is easy and a one-off, 3 or 4 character process:

      my $neverUndef = ''; my $alsoNeverUndef = 0;

      Or when they are assigned:

      my $neverUndef; ... $neverUndef = mightReturnUndef() // '';

      This way, you only need to it once regardless of how many times that value is used; and once they are re-enabled, any "uninitialized" warnings that do crop up are useful rather than annoying.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.