# file:
# bare_blocks.pl
# description:
# this is the file to test semantic of bare blocks
#
# conclusion:
# bare blocks is like a loop which execute only once
# you can use last;next;redo as you can do on loops.
#
use strict;
my $i = 85;
if ($i > 0 and $i < 100) {
{
print "Excellent" and last if $i >= 90;
print "Good" and last if $i >= 80;
print "Fair" and last if $i >= 70;
print "Pass" and last if $i >= 60;
print "Fail" and last if $i < 60;
}
}
perl usage of bare blocks, example 1
最新推荐文章于 2024-08-07 14:12:54 发布
本文通过一个Perl脚本示例介绍了裸块(bare blocks)的概念及其用法。裸块类似于只执行一次的循环结构,可以在其中使用last, next和redo等关键字来控制流程。示例展示了如何基于变量$i的值进行条件判断并输出不同的评价。
259

被折叠的 条评论
为什么被折叠?



