If control structure
Chomp (My $a = <STDIN>); User input variable $a value
if ($a > 0) { If $a is greater than 0 executes command
print "$a is larger than 0\n";
}
elsif ($a = = 0) { if $a equals 0 then execute command
print "$a equals 0\n";
}
else{ If $a is less than 0 execute command
print "$a is smaller than 0\n";
}
Unless control structure in contrast to if action, to execute a command when judged false
Chomp (My $a = <STDIN>);
Unless ($a > 0) {
print "$a is not larger than 0\n";
}
While control structure
$b = 0; Assign a value of variable $b 0
while ($b <) { when $b is less than 20 o'clock execute the command in the
loop $b + +;
Say "$b";
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/
while (<>) { always lets the user input string
if (/fred/) { Print if the string containing "Fred" is entered, print is not printed
;
}
}
Until control structure, which, contrary to the while function, executes the loop when the judgment is false
Until (0) {
print ' test ';
}
foreach Control structure
foreach (1..10) { The list is a value from 1 to 10 and loops print
"$_\n";
}
foreach $str (Qw/hello bye the you/) { loops through the list of strings to print
"$STR \ n";
}
For control structure, similar to foreach
For ($i =10 $i >0; $i-) { variable $i cycles from 10 to 1 and prints print
"$i \ n";
}
This article is from the "Strive for" blog, please be sure to keep this source http://carllai.blog.51cto.com/1664997/1186224