# Perl 中的`unless-else`语句

> 原文： [https://beginnersbook.com/2017/02/unless-else-statement-in-perl/](https://beginnersbook.com/2017/02/unless-else-statement-in-perl/)

类似于[`unless`语句](https://beginnersbook.com/2017/02/unless-statement-in-perl/)，Perl 中的`unless-else`语句与[`if-else`语句](https://beginnersbook.com/2017/02/if-else-statement-in-perl/)相反。在`except-else`中，如果条件为`false`，执行内部语句，如果条件为`true`，则执行`else`内的语句。

```perl
unless(condition) {
   #These statements would execute
   #if the condition is false.
   statement(s);
}
else {
   #These statements would execute
   #if the condition is true.
   statement(s);
}
```

#### 例

```perl
#!/usr/local/bin/perl

printf "Enter any number:";
$num = <STDIN>;
unless($num>=100) {
   #This print statement would execute,
   #if the given condition is false
   printf "num is less than 100\n";
}
else {
   #This print statement would execute,
   #if the given condition is true
   printf "number is greater than or equal to 100\n";
}
```

**输出：**

```perl
Enter any number:100
number is greater than or equal to 100
```