in reply to Perl Gotchas.

This is a pretty common problem with parsers. I know that C parsers have the same sort of problem (see hardburn's comment, above), and Sybase's T-SQL parser's definition of a line is even more approximate, but you get used to it after a while.

In perl a common problem that I've seen is a single missing }, which in a large file is sometimes reported as being missing at the end of the file even though there are a whole bunch of subroutines in the file, and the missing curly is somewhere in the middle...

Michael

Replies are listed 'Best First'.
Re: Re: Perl Gotchas.
by Anonymous Monk on Nov 20, 2003 at 17:22 UTC
    This isn't actually a parser problem, it's an artifact of the language. It's perfectly legal to write subs within subs, so there's no good way for perl to determine when you meant to close off that first curly brace.
      You're quite right.

      But that still makes finding the offending missing curly difficult - which is what this thread is about, no? :-)

      Michael

        It can be hard sometimes, if you write untidy code ;-) If you consistently pay attention to indentation, missing curlies aren't /too/ hard to spot. If, however, you have other people's untidy code (ahuh), you might want to view it with some program like nedit. This program will show you the opening or closing curly, by selecting the other, which would solve your problem too.

        --
        B10m

Re: Re: Perl Gotchas.
by bart (Canon) on Nov 20, 2003 at 21:49 UTC
    In perl a common problem that I've seen is a single missing }, which in a large file is sometimes reported as being missing at the end of the file
    Indeed, it would help if perl would point towards the opening { that is missing the closing brace, instead of pointing towards the end of the file, where the closing } is supposedly missing. I know where the end of the file is, thank you, I don't need anyone to point it out to me.

      A good trick in this case is to insert a } to the end of the file, and find its pair with your text editor. Most editors nowdays can do that (^G in joe; ^K[ in borland (unsure); % in vi; ^F^[b in emacs; } in less). Of course, this won't always work, it might jump to a different place than where the error is, but it's worth a try.