perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

Missing right curly or square bracket wild goose chase

Open jidanni opened this issue 1 year ago • 1 comments

Here the user wastes many minutes searching for the "Missing right curly or square bracket".

$ cat f.pl
sub surrounding_ids {
    $_[0] =~ /^(.*_)(\d)\d\d(\d)\d\d$/ or die;
    my @r;
    for my $x ( 0, 1 ) {
        for my $y ( 0, 1 ) {
	    push @r, sprintf "%s%d00%d00", $1 ,$2 + $x ,$3 + y;
        }
    }
    return @r;
}

$ perl -c f.pl
Missing right curly or square bracket at f.pl line 11, at end of line
syntax error at f.pl line 11, at EOF
f.pl had compilation errors.

S/he thinks, "Maybe the missing bracket is hiding behind an embedded CTRL+H or something. I better use hexdump(1) to see what is really in my file!"

(Yes, best would be Missing "$" sign at "y", f.pl line 6. But at least no missing bracket goose chase please.)

perl5 (revision 5 version 38 subversion 2)

jidanni avatar Feb 24 '24 06:02 jidanni

I agree that the error message is bad. However, Missing "$" sign is not correct either, as your program could be made to parse by just adding more code at the end:

sub surrounding_ids {
    $_[0] =~ /^(.*_)(\d)\d\d(\d)\d\d$/ or die;
    my @r;
    for my $x ( 0, 1 ) {
        for my $y ( 0, 1 ) {
	    push @r, sprintf "%s%d00%d00", $1 ,$2 + $x ,$3 + y;
        }
    }
    return @r;
}
            ;;
        }
    }
    return @r;
}
$ perl -c try.pl
try.pl syntax OK

The correct error is probably something like unterminated y/// operator on line 6.

mauke avatar Feb 24 '24 07:02 mauke