 
- Perl 基础知识
- Perl - 主页
- Perl - 简介
- Perl - 环境
- Perl - 语法概述
- Perl - 数据类型
- Perl - 变量
- Perl - 标量
- Perl - 数组
- Perl - 哈希
- Perl - IF...ELSE
- Perl - 循环
- Perl - 运算符
- Perl - 日期和时间
- Perl - 子例程
- Perl - 参考资料
- Perl - 格式
- Perl - 文件 I/O
- Perl - 目录
- Perl - 错误处理
- Perl - 特殊变量
- Perl - 编码标准
- Perl - 正则表达式
- Perl - 发送电子邮件
- Perl 高级
- Perl - 套接字编程
- Perl - 面向对象
- Perl - 数据库访问
- Perl - CGI 编程
- Perl - 包和模块
- Perl - 流程管理
- Perl - 嵌入式文档
- Perl - 函数参考
- Perl 有用资源
- Perl - 问题与解答
- Perl - 快速指南
- Perl - 有用的资源
- Perl - 讨论
Perl IF...ELSIF 语句
if语句后面可以跟一个可选的elsif...else语句,这对于使用单个 if...elsif 语句测试各种条件非常有用。
使用if 、 elsif 、 else语句时,有几点需要记住。
- if可以有零个或一个else ,并且它必须位于任何elsif之后。 
- 一个if可以有零到多个elsif,并且它们必须位于else之前。 
- 一旦elsif成功,其余的elsif或else都不会被测试。 
句法
Perl 编程语言中if...elsif...else语句的语法是 -
if(boolean_expression 1) {
   # Executes when the boolean expression 1 is true
} elsif( boolean_expression 2) {
   # Executes when the boolean expression 2 is true
} elsif( boolean_expression 3) {
   # Executes when the boolean expression 3 is true
} else {
   # Executes when the none of the above condition is true
}
例子
#!/usr/local/bin/perl
 
$a = 100;
# check the boolean condition using if statement
if( $a  ==  20 ) {
   # if condition is true then print the following
   printf "a has a value which is 20\n";
} elsif( $a ==  30 ) {
   # if condition is true then print the following
   printf "a has a value which is 30\n";
} else {
   # if none of the above conditions is true
   printf "a has a value which is $a\n";
}
这里我们使用相等运算符 == 来检查两个操作数是否相等。如果两个操作数相同,则返回 true,否则返回 false。执行上述代码时,会产生以下结果 -
a has a value which is 100
perl_conditions.htm