Recently I was writing a program to send me text messages when specific teams scored goals in the World Cup. Thanks to several monks who have already help me out with crontab problems :-)

Anyway, looking at some of the source code I noticed a very subtle bug. The program works as follows:

My program contained the code
if ( ($team1_score ne $team1_scorec) or ($team2_score ne $team2_score) + ) { $changed_matches{$team1} = $changed_matches{$team2} = "$team1 vs $team2 ($team1_scorec - $team2_scorec)"; }
Obviously this code contains an error. In the second 'clause' of the 'if' statement, I'm comparing a variable to itself. I meant to write $team2_scorec instead.

So surely the expression $team2_score ne $team2_score is a contradiction--it will never evaluate as true.

So, wouldn't it be good if Perl could warn about this? It would have saved me a lot of trouble.

I suppose it might be possible that a thread could access the variable and change it, but I would imagine that the ne operator would be implemented in a sort of 'atomic' fashion.

I'd be interested to hear your views on this. Would it be difficult to create a pragma to spot contradictions and tautologies as well?


In reply to Should 'use warnings' check for contradictions? by SuperCruncher

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.