Книга: Fedora™ Unleashed, 2008 edition

Comparison Operators

Comparison Operators

The comparison operators used by Perl are similar to those used by C, awk, and the csh shells, and are used to specify and compare values (including strings). Most frequently, a comparison operator is used within an if statement or loop. Perl has comparison opera tors for numbers and strings. Table 25.1 shows the numeric comparison operators and their behavior.

TABLE 25.1 Numeric Comparison Operators in Perl

Operator Meaning
== Is equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
!= Not equal to
.. Range of >= first operand to <= second operand
<=> Returns -1 if less than, 0 if equal, and 1 if greater than

Table 25.2 shows the string comparison operators and their behaviors.

TABLE 25.2 String Comparison Operators in Perl

Operator Meaning
eq Is equal to
lt Less than
gt Greater than
le Less than or equal to
ge Greater than or equal to
ne Not equal to
cmp Returns -1 if less than, 0 if equal, and 1 if greater than
=~ Matched by regular expression
!~ Not matched by regular expression

Оглавление книги


Генерация: 0.601. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз