|
|
||||
![]() | ||||
It is often helpful to be able to display calculated values in an HTML file.
And when using the .IF
command, you will often want to have it act differently based on some logical
condition.
The Document Interface supports a number of arithmetic and logic operators, all of which are actually handled by the Perl language. The operators themselves must not be within either type of quotes, even if the operands are.
Operations are normally evaluated using set rules of precedence. This means that, for instance, multiplication is carried out before addition. To override this, operations can be surrounded by any number of parentheses () to give them precedence. For example, the following operations produce the results on the right:
Operation
Result
Reason
2+3*4
(2+3)*4
2==2 || 1==2 && 3==3 || 3==4
(2==2 || 1==2) && (3==3 || 3==4)14
20
false
truemultiplication * evaluated first
logical AND && evaluated first
The following table lists the operators in order of precedence, with the highest precedence listed at the top. Operations of equal precedence are always evaluated from left to right.
Operator
Description
Example
Result
#string#expression# Returns the portion of string which matches the Perl regular expression, or an empty string if there is no match. For a full description of this advanced feature, see the Perl page on regular expressions. #abcdef#a[bc]#
#abcdef#a.*e#ab
abcde**Exponentiation10**2
4**3100
64!Logical negation (Not)!(1==2)
!1 || !0true
true*
/
%Multiplication
Division
Modulo10*3 + 24/6
10*(3 + 24)/6
11/4
11%434
45
2.75
3+
-
.Addition
Subtraction
String concatenation3+4
3-4
"abc"."ab"."z"7
-1
abcabz<
>
<=
>=
lt
gt
le
geLess than
Greater than
Less than or equal to
Greater than or equal to
Alphabetically less than
Alphabetically greater than
Alphabetically less than or equal to
Alphabetically greater than or equal to1<2
1>2
1+2<=3
1+2>=4
"abc" lt "def"
"abc" ge "a"
"abc" le "abc"
"aBc" ge "abc"true
false
true
false
true
true
true
false==
!=
eq
neEquals
Does not equal
String equals
String does not equal9*5==5
10/3!=3
"abc" eq "Abc"
"abc" ne "abcd"false
true
false
true&&Logical And1+2==3 && 2>1true||Logical Or1+2==3 || 1>2
2==0 && 1==1 || 2==2true
trueAll of the string operators (
lt,ge,ne, etc.) are case-sensitive. You have to enter them in lowercase.When using logical expressions with the
.IFcommand, you should keep in mind that the code contained within the.IFwill not be evaluated if the argument passed to it is either the number0, an empty string, or any of the strings"no","off", or"false"(case does not matter.) This means that all of the following examples produce the same result:<!--.if 0--> <!--.if fALse--> <!--.if 1==99 || 4+4==9-->
Home | Directories | Web Email | Calendar | Campus Map | Search | Help
About the College |
Admission |
Academics |
Student Life |
Athletics Copyright © 2001 Mount Holyoke College. This page created by the OIS Operations Group and maintained by Webmaster. Last modified on November 2, 2001. |