http://www.perlmonks.org?node_id=1036503


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?

Laurent, you think that having warning on for $a eq $b, gives you more useful warnings than false ones?

No. I think that those warnings are useless more often than useful. But sometimes they are useful. And I still prefer to have them when they are useful (maybe only one case out of ten) because they tell me I have a bug in my code or something wrong in my data, even if I have to deal with the more common useless cases.

I had very recently a case where I wanted to remove duplicates from a sorted file. I wrote something like this:

my $previous_line; while (my $current_line = <$DATA>) { print $OUT $current_line unless $current_line eq $previous_line; $previous_line = $current_line; }

And, of course I got a "false" warnings because $previous_line is not defined the first time through the loop. But, so what? How long does it take to change the first line of the code above to something like:

my $previous_line = "";

Ten seconds? I prefer to have these spurious warnings perhaps 9 times out of 10, because they tell me something really useful 1 time out of 10.