- foreach my $person (qw/ fred wilma betty barney dino pebbles /) {
-
eval {
-
open FILE, "<$person"
-
or die "Can't open file '$person': $!";
-
my($total, $count);
-
while (<FILE>) {
-
$total += $_;
-
$count++;
-
}
-
my $average = $total/$count;
-
print "Average for file $person was $average\n";
-
&do_something($person, $average);
-
};
-
if ($@) {
-
print "An error occurred ($@), continuing\n";
-
}
-
}
When a normally fatal error happens during the execution of an eval block, the block
is done running, but the program doesn’t crash.
阅读(399) | 评论(0) | 转发(0) |