?????? ?????
????????ж?
?????????
1??while???
2??until???
3??for???
4??????б?(????)???????foreach???
5??do???
6?????????
7???????goto???
????????????
????????ж?
if ( <expression>) {
<statement_block_1>
}
elsif (
<expression> ) {
<statement_block_2>
}
...
else{
<statement_block_3>
}
?????????
1??while???
while (
<expression> ) {
<statement_block>
}
2??until???
until (
<expression> ) {
<statement_block>
}
3????C??for???
????
for ($count=1; $count
<= 5; $count++) {
# statements
inside the loop go here
}
????????for???????????????????????
for ($line =
<STDIN>, $count = 1; $count <= 3;
$line = <STDIN>, $count++) {
print
($line);
}
??????????????
$line = <STDIN>;
$count = 1;
while ($count <= 3) {
print
($line);
$line =
<STDIN>;
$count++;
}
4??????б?(????)????????????foreach??
?????
foreach localvar
(listexpr) {
statement_block;
}
????
foreach $word (@words) {
if ($word eq
"the") {
print
("found the word 'the'\n");
}
}
???
(1)????????????localvar?????????????????????????????????????????????
(2)??????и????????????????????????????磺
@list = (1, 2, 3, 4, 5);
foreach $temp (@list) {
if ($temp ==
2) {
$temp
= 20;
}
}
???@list??????(1, 20, 3, 4, 5)??
5??do???
do {
statement_block
} while_or_until
(condexpr);
do??????????????????
6?????????
???????last????C?е?break?????????????????????next????C?е?continue?????????PERL???е??????????redo???京?????????????????????????????????????????????redo??????do????в??????á?
7???????goto label;???
????????????
???statement
keyword condexpr??????keyword???if??unless??while??until???磺
print
("This is zero.\n") if ($var == 0);
print
("This is zero.\n") unless ($var != 0);
print
("Not zero yet.\n") while ($var-- > 0);
print
("Not zero yet.\n") until ($var-- == 0);
????????ж?д????棬?????????е??
????? ????? ??
paper | appdir | ssv
亚洲欧美在线