note davido I never intended to say there's something stylistically or idiomatically wrong with using parens with the [open] (or any other) function. [perlstyle] states that it is stylistically good to "Omit redundant punctuation as long as clarity doesn't suffer." But a few paragraphs later says, "...just because you CAN omit parenthesis in many places doesn't mean you should." But the example given is a situation with many levels of nested functions. <p> [perlop] has this to say by way of introduction to "or": <p> <blockquote><em>As more readable alternatives to && and || when used for control flow, Perl provides and and or operators (see below). The short-circuit behavior is identical. The precedence of "and" and "or" is much lower, however, so that you can safely use them after a list operator without the need for parentheses...</em></blockquote> <p> Here is a key section of [perlop]: <p> <blockquote><em> Binary "or" returns the logical disjunction of the two surrounding expressions. It's equivalent to || except for the very low precedence. This makes it useful for control flow: <p> <code>print FH $data or die "Can't write to FH: $!";</code> <p> This means that it short-circuits: i.e., the right expression is evaluated only if the left expression is false. Due to its precedence, you should probably avoid using this for assignment, only for control flow. <p> <code> $a = $b or $c; # bug: this is wrong ($a = $b) or $c; # really means this $a = $b || $c; # better written this way </code> <p> However, when it's a list-context assignment and you're trying to use "||" for control flow, you probably need "or" so that the assignment takes higher precedence. <p> <code> @info = stat($file) || die; # oops, scalar sense of stat! @info = stat($file) or die; # better, now @info gets its due </code> <p> Then again, you could always use parentheses. </em></blockquote><p> [perlopentut] says:<p><blockquote><em> If you prefer the low-punctuation version, you could write that this way: <p> <code> open INFO, "< datafile" or die "can't open datafile: $!"; </code> </em></blockquote><p> [perlfunc] [open] recommends 'or' but then shows examples with both 'or' and '||'. <p> My own reason for asserting it is amost always considered better is for several reasons: First, I can see the logic of it; it allows you to not worry about whether you have parenthesis in place. Second, it reads better; 'do this or that' makes for clearer reading than 'do this || that'. Third, after posting the original node, I received comments by several people reminding me that I should increase my emphasis on using 'or' in favor of '||' with open and in other flow-control places because it reduces the ambiguity of precedence. There is no question that "or" is going to be near the bottom of the precedence ladder, whereas "||" is quite a bit higher, and thus, one has to remember when constructing complex logical short-circuit operations which operators are going to bind more closely and which are going to bind less tightly. <p> Perhaps "almost always" is too generous. But I do believe it is clearer, cleaner, less ambiguous, and less prone to context problems. 'or' probably shouldn't be used for "assignment" purposes (the examples above show this). But it seems to be a good choice for many logical flow needs. <p> <div class="pmsig"><div class="pmsig-281137"> <font size=-1><br><p>Dave</p><br> "If I had my life to do over again, I'd be a plumber." -- Albert Einstein</font> </div></div> 301355 301874