Perl 除非语句后可以跟可选的 else 语句,该语句在布尔表达式为true时执行。
unless...else - 语法
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块。
unless...else - 流程图
unless...else - 示例
#!/usr/local/bin/perl$a=100; # check the boolean condition using unless statement unless( $a == 20 ) {# if condition is false then print the followingprintf "given condition is false\n"; } else { # if condition is true then print the followingprintf "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 followingprintf "a has a false value\n"; } else {# if condition is true then print the followingprintf "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 语句函数 - 无涯教程网无涯教程网提供Perl 除非语句后可以跟可选的 else 语句,该语句在布尔表达式为true时执行。 unless.....https://www.learnfk.com/perl/perl-unless-else-statement.html