My second programming teacher (Basic on CommodeDoor if you insist I age myself) had a wonderful way of asking me questions in the grand greek tradition to make me answer my own questions. He rocked so in Mr McGuire's manner I ask:

Ok I have to be declarative, I can't stand it. =) The flaw in your example is that you aren't controlling the issue in the correct place. If you wish to use some_sub() as numeric, make sure it returns a numeric value. Warnings are a contract with yourself, keep the contract at both ends. If you are explicitly ignoring a return (i.e. if the sub could return both 0 and undef) then don't get hung up on making that choice explict.

Also, while you are benchmarking, try the same test with warnings on and off and try turning the warnings on and off within the loop you test as well.

I'm willing to go out on a limb and bet the bit-flag test that defined() does is way cheaper than turning on and off warnings and _majorly_ cheaper than printing errors.

Perl is still doing the test for defined, it has to for greater than so it knows to promote $_ to 0 for the comparison. All you did is ask for the result of that test.

--
$you = new YOU;
honk() if $you->love(perl)


In reply to Re: To warn or not to warn, that is the question by extremely
in thread To warn or not to warn, that is the question by Ovid

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.