Section 1.7. Operators


1.7. Operators

NASL provides arithmetic, comparison, and assignment operators. These operators are explained in the following sections.

1.7.1. Arithmetic Operators

Here are the common arithmetic operators:


+

Used to add numbers. It can also be used to perform string concatenation.


-

Used to perform subtraction. It can also be used to perform string subtraction. For example, 'cat, dog, mouse' - ', dog' results in the string 'cat, mouse'.


*

Used to multiply numbers.


/

Used to divide numbers. Note that NASL will return a 0 if you try to divide by zero.


%

Used to perform a modulo operation. For example, 10%3 computes to 1.


**

Used to perform exponentiation. For example, 2**3 computes to 8.


++

Used to increment a variable's value by 1. When a variable is prefixed by this operator (example: ++c), its value is incremented before it is evaluated. When a variable is post-fixed by this operator (example: c++), its value is incremented after it is evaluated.


Used to decrement a variable's value by 1. When a variable is prefixed by this operator (example: --c), its value is decremented before it is evaluated. When a variable is post-fixed by this operator (example: c--), its value is decremented after it is evaluated.

1.7.2. Comparison Operators

Here are the common comparison operators:


>

Used to test whether a given value is greater than the other.


>=

Used to test whether a given value is greater than or equal to the other.


<

Used to test whether a given value is less than the other.


<=

Used to test whether a given value is less than or equal to the other.


==

Used to test whether a given value is equal to the other.


!=

Used to test whether a given value is not equal to the other.


><

Used to test whether a given substring exists within a string. For example, '123'><'abcd123def' evaluates to TRUE.


>!<

Used to test whether a given substring does not exist within a string. In this case, '123'>!<'abcd123def' evaluates to FALSE.


=~

Used to match a regular expression. Using this operator is similar to calling the ereg( ) function call, which performs a similar operation. For example, the statement str =~ '^[GET / HTTP/1.0\r\n\r\n][.]*') evaluates to TRUE only if str begins with the string GET / HTTP/1.0\r\n\r\n.


!~

Used to test whether a regular expression does not match. It is the opposite of the =~ operator.


[]

Used to select a character from a string by index. For example, if mystring is a1b2c3, mystring[3] evaluates to 2.

1.7.3. Assignment Operators

Here are the common assignment operators:


=

Used to assign a value to a variable.


+=

Used to increment a variable's value. For example, a += 3 increments the value of a by 3, and is equivalent to the statement a = a + 3.


-=

Used to decrement a variable's value. For example, a -=3 decrements the value of a by 3, and is equivalent to the statement a = a - 3.


*=

Used to multiply a variable's value by a specified value. For example, a *= 3 causes the variable a to be assigned a value equal to itself multiplied by 3, and is equivalent to the statement a = a * 3.


/=

Used to divide a variable's value by a specified value. For example, a /=3 causes the variable a to be assigned a value equal to itself divided by 3, and is equivalent to the statement a = a / 3.


%=

Used to assign a variable a value equal to the remainder of a division operation between itself and a specified value. For example, a %=3 causes the variable a to be assigned a value that is equal to the remainder of the operation a/3, and is equivalent to the statement a = a % 3.



Network Security Tools
Network Security Tools: Writing, Hacking, and Modifying Security Tools
ISBN: 0596007949
EAN: 2147483647
Year: 2006
Pages: 110

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net