perl usage of bare blocks, example 1

# 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)