On Tue, 25 Sep 2001, Christine Lenda wrote:

> I remember someone mentioning that there may be a
> precedence problem with "unexpected results" during a
> mathematical conditional test, using the keywords
> "and" and "or"...instead of the symbols (&& and ||).
> Is this true?  Can anyone give me an example?

Yes, || and && have a higher precedence than 'and' and 'or'.  This can
especially be a problem when you are doing an assignment, since = has a
higher precedence than 'and' and 'or', but lower than || and &&, so these
two statements are NOT the same:

my $error = last_error() || next_error() || 'NONE;;
my $error = last_error() or next_error() or 'NONE';

(the second would assign the return value of last_error to $error first,
then do the ors after it).

but

my $error = (last_error() or next_error() or 'NONE');

would do what you expect (do the stuff inside the parentheses and then
assign)

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
A woman may very well form a friendship with a man, but for this to endure,
it must be assisted by a little physical antipathy.
                -- Nietzsche


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to