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.

Get Network Security Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.