Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^3: comparison with bitwise operatorsby Marshall (Canon) |
on Jan 14, 2011 at 03:32 UTC ( [id://882280]=note: print w/replies, xml ) | Need Help?? |
I think we are in agreement. I was keying on the OP's statement of the problem: "compare a value to two numbers". The proposed formulation is very, very good! I see no reason to "improve" it.
For efficiency, with a much larger set of possibilities, "does value X exist within a data set?", I would think that the List::MoreUtils qw (any); solution is the best for two reasons: The Perl "or" code will also "give up" and stop processing immediately upon the first successful match (OR condition is satisfied). I think this is just fine for say 1/2 dozen "or" conditions. Of course the expected probability of returning "true" should be taken into account in the ordering of an "if" statement. This may result in faster code than using say the "smart match" operator in Perl 5.10. Benchmark the program if there is any doubt.
In Section
Seekers of Perl Wisdom
|
|