When I said, Your point about 0.0 is well taken. That meant that you are correct about 0.0. Quite correct, an omission on my part.

The reason why I mentioned the 0E0 case is: If I write code that can return a float like 0.001 or 0.0 (or a string that represents a float), usually the logical test is gonna involve more that just: if ($var), the test will have some >= or <= operators that will force the $var comparison into a numeric context and the "if" test is upon that numeric comparison. Often a range of values to decide that the number is "close enough" to be considered zero for this application's purposes. However, I could imagine some application where the test is a regex.

0E0 is a bit different in that this value is returned when an integer is expected. I have no idea of what say 0.5 of a DBI result would be! So the reason for the mention is that this is a common value from the DBI and therefore there more chance for a coding mistake. if ($num_results) just says that the operation succeed, to find out how many results, if ($num_results >0) would be more appropriate. Probably both tests are needed to decide that "operation worked" and "returned no results".

I didn't think that 0E0 was totally irrelevant. When I said: But it seems that we have tripped over something in a different direction. Folks using the DBI should be aware of this 0E0 stuff. I was trying to re-enforce your point with a common situation in DBI code that may trip up some folks who would otherwise nonchalantly navigate the floating point comparison pitfalls. I don't intentionally use T/F comparisons of (000.000) float values and figured that situation is much less common than this strange "integer" return from the DBI.

Thanks for your addition of 0.0. It was correct and helpful.


In reply to Re^7: Best Hash Practices? by Marshall
in thread Best Hash Practices? by DamianKaelGreen

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.