asked on
sub errorIDsInCatchblocks{
my ($file) = @_;
my ($state, $ind);
open (FILE, $file) or die "could not open $file: $!\n";
my @data = <FILE>;
close(FILE);
my $lineno = 0;
my $result;
my $line;
foreach $line (@data){
$lineno++;
if ($line =~ /^(\s*)try\b/) {
$ind = $1;
$state = 'try';
} elsif ($state eq 'try' and m{^\s*catch}) {
$state = 'catch';
} elsif ($state eq 'catch' and m{\strcmp\b}) {
$result = 'Fail';
} elsif ($state and m{^${ind}end}) {
$state = undef;
$result = 'Pass';
}
}
return $result;
}