In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shares with you the contents of the instructions on the selective control structure of Perl. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Perl selective control structure
The selective control structure includes if and unless statements, similar to if in C language.
First of all, let's introduce the definition of true and false. In Perl, these rules are somewhat difficult to understand. When the value of the control expression is an empty string or 0, the expression is false, and in any other case, the value of the expression is true.
Note: "00" is not an empty string or 0, the value is true. The same is true of "0.0".
Instruction: if if
Grammar one:
If (discriminant expression)
{
A block of statements when the expression is true
}
The previous syntax can also be written in Perl as: if (discriminant expression) when the expression is true.
Example:
Print "Please enter your score?\ n"; $scorre=;# stands for standard input and will allow the user to enter a string chop ($score); # remove a newline character from $score***\ nDelete if ($score > = 60) {print "your score passed!\ n";}
It can also be written as: print "your score passed!\ n" if ($score > = 60)
Grammar 2:
If (discriminant formula 1) {
The block of statements when discriminant one is true
} else {
A statement block when discriminant one is false.
}
Example:
Print "Please enter your score?\ n"; $scorre=; chop ($score); if ($score > = 60) {print "your score passed!\ n";} else {print "your score failed!\ n";}
Grammar 3:
If (discriminant formula 1)
{
The block of statements when discriminant one is true
} elsif (discriminant formula 2) {
The statement block when discriminant 2 is true
} elsif (discriminant expression 3) {
The statement block when discriminant 3 is true
} else {
Statement blocks when all discriminants are false
}
Example:
Print "Please enter your score?\ n"; $scorre=; chop ($score); if ($score > 60) {print "your score is greater than 60!\ n";} elsif ($score)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.