On Tue, Jan 16, 2001 at 11:49:46PM -0500, Scott R. Godin wrote:
> fails:
> my $GameType = param('mapstyle') or $default_mapstyle;
>
>
> works:
> my $GameType = param('mapstyle') || $default_mapstyle;
>
> Am I mistaken in assuming that "I should use 'or' because this is 'string
> values'" or does this happen "simply because the possibility of returning
> undef exists in the expression" ?
According to the precedence table in perlop, = binds tighter than or but
looser than ||. Your code is equivalent to:
(my $GameType = param('mapstyle')) or $default_mapstyle;
my $GameType = (param('mapstyle') || $default_mapstyle);
Thus, you should either use ||, or add parentheses (or both, if you really
want to).
The only difference between || and or is precedence. Both are boolean
operators. The gt vs. < distinction does not apply; that's only for
comparison operators.
Ronald