Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: AND OR

by Tanktalus (Canon)
on May 14, 2006 at 04:59 UTC ( #549292=note: print w/replies, xml ) Need Help??


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.
Just my 2 cents CDN.

Replies are listed 'Best First'.
Re^2: AND OR
by hasimir44 (Sexton) on May 14, 2006 at 05:09 UTC
    That's exactly what I wanted. Thanks for the detail. Perl is cooler than river dancing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://549292]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2023-09-24 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?