Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
In what order is a compound IF evaluated - right-to-left or left-to-right?
Does Perl immediately stop evaluating a compound IF once a false evaluation occurs?
I am building an IF statement of at least 10 comparisons and want it to evaluate as fast as possible.
A similar example:
if (($A ne "ONE") && ($B eq "TWO")) { ... } else { ... }
So, if the odds are that ($A ne "ONE") will fail more often, should I write:
if (($A ne "ONE") && ($B eq "TWO"))
-or- should I write:
if (($B eq "TWO") && ($A ne "ONE"))
Does it matter - does Perl care???
thanks...
-mike
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: In what order is a compound IF evaluated?
by diotalevi (Canon) on Jul 09, 2004 at 22:03 UTC | |
|
Re: In what order is a compound IF evaluated?
by Old_Gray_Bear (Bishop) on Jul 09, 2004 at 22:32 UTC | |
|
Re: In what order is a compound IF evaluated?
by shemp (Deacon) on Jul 09, 2004 at 22:08 UTC | |
by jonadab (Parson) on Jul 10, 2004 at 14:10 UTC | |
|
Re: In what order is a compound IF evaluated?
by runrig (Abbot) on Jul 09, 2004 at 23:00 UTC |