According to the perl man pages, perl DOES use short circuit evaluation on &&, AND, ||, OR. The only difference between the C-style and the others is the precedence (the words have very low precedence). Short circuit evaluation means that perl will only evaluate the second part of the expression if it needs to. In an AND statement, if the first part is false the whole statement is false, so it doesn't need to evaluate the second part. In an OR statement, if the first part is true the whole statement is true, so it doesn't need to evaluate the second part. This is used frequently by experienced perl coders for statements like:
Code:
open(FILE,$filename) or die("Couldn't open file");
If the open is successful (returns true) then the die will NOT be executed. If the open is unsuccessful (returns false) then the die WILL be executed. You'll see this a LOT. Tracy Dryden
tracy@bydisn.com
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.