On Tue, Jun 05, 2001 at 02:04:59PM -0700, Hanz, Rob wrote:
> Actually, there's a pretty good reason to use 'or' instead of '||' - for
> anything in list context, remember that '||' binds more tightly than ','
> and 'or' binds less tightly than ','.
>
> This can lead to bugs if you do things like:
>
> print OUTFILE $variable || die "Error writing to $nameofmyoutfile ";
The original discussion was regarding the alternatives:
open(FILE, $file) || die("open: $!");
open FILE, $file or die "open: $!";
This is the matter of style of style being discussed. Naturally, if you're
not using parens, the choice of 'or' or '||' becomes a little more
important.
Your basic premise, that there's a pretty good reason to use 'or' instead of
'||', tries to generalize the problem too much. There are instances where
it's much preferable to use '||', for the very reason you mention preferring
'or', precedence. Consider:
$foo = undef || "default";
$foo = undef or "default";
The alternative to using '||', while still accomplishing what was intended,
is, of course:
$foo = (undef or "default");
I think you can guess which I prefer.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--