Perl UNLESS statement
Unless a statement consists of a Boolean expression followed by one or more statements.
grammar
The syntax is as follows:
unless(boolean_expression){ # 在布尔表达式 boolean_expression 为 false 执行 }
Boolean_expression If the Boolean expression is false, if statement within the code block will be executed. If the Boolean expression is true, if the first set of codes after the statement (after the close parenthesis) will be executed.
flow chart
Examples
#!/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";
The above program, the output is:
a 大于等于 20 a 的值为 : 20 条件 a 为 false a 的值为 :