in reply to When is 'eval' too inefficient?
Using eval is almost always overkill, especially when your data already has a well-defined structure. In your case, you seem to be using floating point numbers, so you might want:
my $increment = ($var1 + 0) || $var2; $value += $increment;
If your numbers are actually strings being read in from a file, an explicit string comparison might be even more explicit:
my $increment = ($var1 ne '0.00') ? $var1 : $var2;
The rule of thumb is to always avoid the string form of eval, because there are almost always more efficient ways around it unless you need to parse arbitrary Perl code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: When is 'eval' too inefficient?
by argv (Pilgrim) on Oct 12, 2007 at 15:04 UTC | |
by ikegami (Patriarch) on Oct 12, 2007 at 15:18 UTC | |
by ikegami (Patriarch) on Oct 12, 2007 at 15:34 UTC |