Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Do people find warning for undef with string compare useful?

by Laurent_R (Prior)
on Jun 01, 2013 at 21:17 UTC ( #1036503=note: print w/ replies, xml ) Need Help??


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.


Comment on Re^3: Do people find warning for undef with string compare useful?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036503]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-04 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls