My gut feeling when I read this was that there was going to be a pretty serious impact on program speed; but assuming my
Benchmarking isn't totally silly, there is no significant efficiency loss:
use strict;
use Benchmark;
timethese(100000, {
'Using Eval' => 'eval { &test or die }; $@ and warn("maths
+sux:$@");',
'using or' => '(&test) or warn("maths sux:$@");',
});
sub test {
#A test which always returns true
for(1..100) {($_>0) || return 0}
return 1;
}
boldra@trinity:~/workspace$ ./eval_test.pl
Benchmark: timing 100000 iterations of Using Eval, using or...
Using Eval: 10 wallclock secs ( 6.46 usr + 0.06 sys = 6.52 CPU)
using or: 10 wallclock secs ( 6.28 usr + 0.11 sys = 6.39 CPU)
It does, however, look pretty messy to (IMHO) do this for every subroutine call, and it doesn't allow me to put non-fatal errors in my subroutines.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.