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 : 

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

技术教程推荐

趣谈网络协议 -〔刘超〕

机器学习40讲 -〔王天一〕

邱岳的产品实战 -〔邱岳〕

TypeScript开发实战 -〔梁宵〕

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

图解 Google V8 -〔李兵〕

数据中台实战课 -〔郭忆〕

业务开发算法50讲 -〔黄清昊〕

现代C++20实战高手课 -〔卢誉声〕

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