On Wed, Jul 25, 2001 at 03:58:01PM -0700, Stephanie Stiavetti wrote:
> you know, our super webmaster perl guy said that you shouldn't use || in
> die statements, because in the order of precedence || comes before 'or'
> and that in a die statement, it can mess things up.
Other than this statement, I will try not to comment on taking programming
advice from someone whose official title is "webmaster". ;)
While it's true using '||' in a die statement, or any other statement, can
mess things up, it's only because the operator is being misunderstood or
misused (both of which can mess pretty much -anything- up). Either your
webmaster doesn't understand truly why, he's trying to instill some
religious coding dogma, or you didn't understand his explanation. You can
use '||' and 'or' in a die statement, or any other statement, so long as you
understand the precedence rules involved, or are willing to use parentheses
to disambiguate.
This is fine:
open FILE, $file or die "open failed: $!";
it's parsed as:
open(FILE, $file) or die("open failed: $!");
This is not fine:
open FILE, $file || die "open failed: $!";
because it's parsed as:
open(FILE, $file || die("open failed: $!"));
'||' has higher precedence than the list operator 'open' (functions in Perl
are actually operators) so it is evaluated first, yielding the term:
$file || die...
Then the open is evaluated. It has two terms, "FILE", and "$file || die..".
> now, I question his opinion seeing as how EVERYONE uses || instead of 'or'.
> can you clarify?
Everyone? I use '||' and, judging from this list, appear to be in the
minority.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]