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 toTRUE.-
>!< Used to test whether a given substring does not exist within a string. In this case, '
123'>!<'abcd123def' evaluates toFALSE.-
=~ 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 statementstr =~ '^[GET / HTTP/1.0\r\n\r\n][.]*')evaluates toTRUEonly ifstrbegins with the stringGET / 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
mystringisa1b2c3,mystring[3]evaluates to2.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access