Avatar of Tolgar
Tolgar

asked on 

How to fix Use of uninitialized value in string issue in Perl?

Hi,
Why do I get "Use of uninitialized value in string eq at ....." for line 15 for the following code?

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;	
}

Open in new window

Perl

Avatar of undefined
Last Comment
Tolgar

8/22/2022 - Mon