rucker has asked for the wisdom of the Perl Monks concerning the following question:

I've run across this problem a few times and I'm wondering if anyone has tips for dealing with this.

Basically what happens is I'll make a large number of changes (manually apply some patches, for instance) and I'll try perl -Tc file.pl. It dies with "Undefined subroutine &main::reallyisdefined..."

Now reallyisdefined REALLY IS DEFINED, so that's not the problem. It is in a seperately "require"d file, that file checks out fine (and in fact it wasn't changed).

I'm sure that if I spend the time looking at the code line by line, eventually I will find a syntax error in file.pl, but isn't there an easier way?

No, I'm not going to post the code, we're taking about > 15k lines.

  • Comment on Tips for dealing with bogus syntax errors

Replies are listed 'Best First'.
Re: Tips for dealing with bogus syntax errors
by OM@HAL2001 (Novice) on Aug 10, 2001 at 12:10 UTC

    Even without posting the whole code, are you able to reproduce the same behaviour in the fewest lines of code as possible?

    Also, you could try to run your script with strict and warnings on:

    perl > 5.6+
    perl -Tc -Mstrict -Mwarnings -Mdiagnostics file.pl
    perl < 5.6
    perl -Twc -Mstrict file.pl
    And see what it does.
    Note also that perl generated syntax errors are really seldomly bogus! :)

    Cheers,
    OeufMayo, live from HAL2001

      Unfortunately your tips don't help in this instance. I can't reproduce the behavior from scratch, and I've only seen it happen with this one project. I've used perl enough to know that it seldomly generates bogus errors. If it often did, I wouldn't be asking this question because I'd already know the "secrets" ;) This reminds me of times using gcc when it would locate an error in whatever.h, when there was a syntax error in another previously included .h. (Maybe I'm just dense.)
Re: Tips for dealing with bogus syntax errors
by rucker (Scribe) on Aug 09, 2001 at 21:12 UTC
    eh.. ok, well right after I submitted this, I commented out the BEGIN block, and what do you know? perl -Tc gave me the right syntax error.

    Still, if you have a tip for diagnosing these sorts of odd errors, let me know.

    Thanks!

Re: Tips for dealing with bogus syntax errors
by kjherron (Pilgrim) on Aug 14, 2001 at 01:18 UTC
    "bogus errors" are often caused by an unclosed string literal or an unbalanced bracket somewhere. Probably the best way to find these is with a syntax-highlighting text editor.

    If you're an old dinosaur like me and don't use a syntax-highlighting editor, another way is to just start commenting out blocks of code and running the script through "perl -c". When you comment out the bad line, the error that you're tracking will go away. Then you can comment out progressively smaller blocks of code until you've narrowed the field sufficiently.