Keep It Simple, Stupid | |
PerlMonks |
Re: To warn or not to warn, that is the questionby extremely (Priest) |
on Dec 03, 2000 at 14:11 UTC ( [id://44657]=note: print w/replies, xml ) | Need Help?? |
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. --
In Section
Seekers of Perl Wisdom
|
|