Книга: Fedora™ Unleashed, 2008 edition
if/else
if/else
The syntax of the Perl if/else
structure is as follows:
if (condition) {
can be a statement that returns a true or false value.
statement or block of code
} elsif (condition) {
statement or block of code
} else {
statement or block of code
}
condition
Truth is defined in Perl in a way that might be unfamiliar to you, so be careful. Every thing in Perl is true except 0
(the digit zero), "0"
(the string containing the number 0
), ""
(the empty string), and an undefined value. Note that even the string "00"
is a true value because it is not one of the four false cases.
The statement or block of code is executed if the test condition returns a true value. For example, Listing 25.3 uses the if/else
structure and shows conditional statements using the eq
string comparison operator.
LISTING 25.3 if/elsif/else
if ($favorite eq "chocolate") {
print "I like chocolate too.n";
} elsif ($favorite eq "spinach") {
print "Oh, I don't like spinach.n";
} else {
print "Your favorite food is $favorite.n";
}
- Пример 4-7. Использование команды shift
- Листинг 8.2. Общий код, используемый во всех приведенных ниже вариантах тестов
- Что вы узнаете
- Технологии
- Листинг 8.1. Применение отложенной загрузки, кэширования и освобождения графических ресурсов
- A7.6. Мультипликативные операторы
- 9.5. Инженерия разработки программного продукта
- Благодарности
- Lesson Summary
- CMYK
- 9.5. Полномочия
- 2. Управление каналами распределения и продаж