Perl UNLESS 语句

Perl 教程 · 2019-02-26 20:12:04

一个 unless 语句由一个布尔表达式后跟一个或多个语句组成。

语法

语法格式如下所示:

unless(boolean_expression){
   # 在布尔表达式 boolean_expression 为 false 执行
}

如果布尔表达式 boolean_expression为 false,则 if 语句内的代码块将被执行。如果布尔表达式为 true,则 if 语句结束后的第一组代码(闭括号后)将被执行。

流程图

实例

#!/usr/bin/perl $a = 20; # 使用 unless 语句检测布尔表达式 unless( $a < 20 ){ # 布尔表达式为 false 时执行 printf "a 大于等于 20\n"; } print "a 的值为 : $a\n"; $a = ""; # 使用 unless 语句检测布尔表达式 unless ( $a ){ # 布尔表达式为 false 时执行 printf "条件 a 为 false\n"; } print "a 的值为 : $a\n";

执行以上程序,输出结果为:

a 大于等于 20
a 的值为 : 20
条件 a 为 false
a 的值为 :

点击查看所有 Perl 教程 文章: https://codercto.com/courses/l/19.html

查看所有标签

HTTP

HTTP

David Gourley、Brian Totty、Marjorie Sayer、Anshu Aggarwal、Sailu Reddy / O'Reilly Media / 2002-10-7 / USD 54.99

Product Description Web technology has become the foundation for all sorts of critical networked applications and far-reaching methods of data exchange, and beneath it all is a fundamental protocol......一起来看看 《HTTP》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具