Perl 除非语句后可以跟可选的 else 语句,该语句在布尔表达式为true时执行。
Perl编程语言中的unless... else 语句的语法为-
unless(boolean_expression) { # statement(s) will execute if the given condition is false } else { # statement(s) will execute if the given condition is true }
如果布尔表达式的值为 true ,则将执行代码的除非块,否则将执行代码的 else块。
链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-unless-else-statement.html
来源:LearnFk无涯教程网
#!/usr/local/bin/perl $a=100; # check the boolean condition using unless statement unless( $a == 20 ) { # if condition is false then print the following printf "given condition is false\n"; } else { # if condition is true then print the following printf "given condition is true\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"; } else { # if condition is true then print the following printf "a has a true value\n"; } print "value of a is : $a\n";
执行以上代码后,将产生以下输出-
given condition is false value of a is : 100 a has a false value value of a is :
这一章《Perl - 条件判断 - unless...else 语句函数》你学到了什么?在下面做个笔记吧!做站不易,你的分享是对我们最大的支持