laziness, impatience, and hubris | |
PerlMonks |
Re: Newbie questionby syphilis (Archbishop) |
on Aug 23, 2022 at 11:08 UTC ( [id://11146307]=note: print w/replies, xml ) | Need Help?? |
As an example, I have used the absolute value function abs but I could have used abs($_). Which is best? Does it matter? It doesn't really matter which you use - either way, the same code gets executed. Interestingly, there's no need to call on the abs() function at all. You could replace: That will work fine because the "-" character evaluates to zero in numeric context, anyway. With that change (and the other previously mentioned correction) in place, the script then outputs: The warnings can be silenced by inserting: into the oddDigitSum() subroutine: Note that any "numeric" warnings triggered from outside the oddDigitSum() subroutine are still enabled. I'm not sure which approach is the most efficient - you could use Benchmark; to find out, if you want. I expect there's not much difference performance-wise. Cheers, Rob
In Section
Seekers of Perl Wisdom
|
|