Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
628 views
in Technique[技术] by (71.8m points)

include - Why SSI condition != || != doesn't work?

I can't get working this conditional expression

<!--#if expr="$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html" -->

while this one without ! before = works perfect

<!--#if expr="$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html" -->

What's the problem? I get no error simply != doesn't work though || with other condition but works for single condition.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is because = and != are hardly the same operator. Note that, by De Morgan's law (which I also explained in this old post),

a != b || c != d

is equivalent to

a = b && c = d

which is never true for x = a && x = b where a != b.

Changing the binary operator requires changing the conditionals as well to be equivalent.

Thus, by the above logic,

$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html

is equivalent to

$DOCUMENT_NAME=index.html && $DOCUMENT_NAME=links.html

which cannot be true as $DOCUMENT_NAME can be "index.html" or "links.html" but not both.

However, the 2nd snippet,

$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html

"works" because there is not the logical never-true fallacy mentioned above. It will be true when $DOCUMENT_NAME is either "index.html" or "links.html".


Some languages/values will violate the above equivalency .. but that is another topic.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...