5.10. Perl conditional statement

发布时间 :2023-10-20 23:00:03 UTC      

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

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.

Powered by Django & PostgreSQL (with PostGIS)