in reply to AND OR
I'm not sure what you mean "like shell scripting"... Conceptually, they're the same idea, although their implementation details are incredibly different.
Your example, if (($val > 5) && ($val < 10)) { ... } probably does what you expect: execute the "..." part if $val is numerically between 5 and 10, exclusive.
Notes:
- The extra parenthesis aren't needed. They don't hurt, either. i.e., if ($val > 5 && $val < 10) { ... } is fine.
- && can be written and. Conceptually, these two operators do the same thing, but they are distinct for a reason: they have different precedence. So they're not completely interchangeable. Though, in if-clauses such as this, they usually are interchangeable.
- I find it a wee bit more readable to follow numbers from left to right in increasing values. e.g., if (5 < $val and $val < 10) { ... } This just seems more natural to me as a human reader, even though it doesn't seem natural to most programmers who have learned that they need to break up the mathematical term "5 < V(x) < 10" or whatever into two distinct tests.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: AND OR
by hasimir44 (Sexton) on May 14, 2006 at 05:09 UTC |
In Section
Seekers of Perl Wisdom