in reply to Re^4: Do people find warning for undef with string compare useful?
in thread Do people find warning for undef with string compare useful?
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.
|
|---|