Perl 中的 unless 语句函数

首页 / Perl入门教程 / Perl 中的 unless 语句函数

Perl的除非unless语句由一个布尔表达式和一个或多个语句组成。

unless - 语法

Perl编程语言中的exclude语句的语法是-

unless(boolean_expression) {
   # statement(s) will execute if the given condition is false
}

如果布尔表达式的输出为 false ,则将执行exclude语句中的代码块。

unless - 流程图

Perl unless statement

unless - 示例

#!/usr/local/bin/perl
 
$a=20;
# check the boolean condition using unless statement
unless( $a < 20 ) {
   # if condition is false then print the following
   printf "a is not less than 20\n";
}
print "value of a is : $a\n";

$a="";
# check the boolean condition using unless statement
unless ( $a ) {
   # if condition is false then print the following
   printf "a has a false value\n";
}
print "value of a is : $a\n";

首先,除非语句使用小于运算符(<),该运算符比较两个操作数,如果第一个操作数小于第二个操作数,则返回true,否则返回false。 

a is not less than 20
value of a is : 20
a has a false value
value of a is : 

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Linux实战技能100讲 -〔尹会生〕

说透中台 -〔王健〕

现代C++编程实战 -〔吴咏炜〕

说透敏捷 -〔宋宁〕

分布式数据库30讲 -〔王磊〕

高楼的性能工程实战课 -〔高楼〕

大数据经典论文解读 -〔徐文浩〕

Tony Bai · Go语言第一课 -〔Tony Bai〕

反爬虫兵法演绎20讲 -〔DS Hunter〕

好记忆不如烂笔头。留下您的足迹吧 :)