5.10. Perl conditional statement

发布时间 : 2025-10-25 13:33:04 UTC      

Page Views: 9 views

Perl conditional statement is the result of the execution of one or more statements True or False to determine the block of code to execute

You can use the following figure to briefly understand the execution of conditional statements:

/media/sphinx_tuto/img/Q1hUjVgberLytG0p.png

Note that the number 0, string '0' "" , empty list() , and undef for false all other values are true . true previous use ! or not then return to false .

Perl provide the following conditional statements are provided:

Statement

Description

If statement

An if statement consists of a Boolean expression followed by one or more statements.

If…else statement

An if statement can be followed by an optional else statement, and the else statement is executed when the Boolean expression is false.

If…elsif…else statement

You can follow an if statement with an optional elsif statement, followed byanother else statement.

Unless statement

A unless statement consists of a Boolean expression followed by one or more statements.

Unless…else statement.

An unless statement can be followed by an optional else statement.

Unless…elsif..else statement

An unless statement can be followed by an optional elsif statement, followedby another else statement.

Switch statement

In the latest version of Perl, we can use the switch statement. It executes the corresponding block of code according to different values.

5.10.1. Ternary operator?: #

We can use conditional operations ? : to simplify if...else operation statement. The usual format is:

Exp1 ? Exp2 : Exp3; 

If Exp1 the expression is true , then return Exp2 expression evaluates the result, otherwise returns Exp3 .

The example is as follows:

Example #

#/ Usr/local/bin/perl $name="Rookie Tutorial"$ Favorite=10# Number of likes $status=($favorite>60)? Popular website ":" Not a popular website "; Print "$name - $status n"; 

Execute the above program, and the output is as follows:

Novice Tutorial - Not a Popular Website 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。