go ahead... be a heretic | |
PerlMonks |
Grokking Compile Error Messagesby QM (Parson) |
on Jul 21, 2004 at 15:35 UTC ( [id://376286]=perlmeditation: print w/replies, xml ) | Need Help?? |
I came across a compile error today (OK, actually, I generated it, so who else was going to find it?) that took me some time to fix. I thought this would be a good place to gather similar examples of awkward or dense compile errors from everyone here.
Here's the error report (sorry for the wrapping): Being trained from an early age on various "old school" compilers (MS Pascal version 1, for instance), generally one should avoid even looking at errors beyond the 1st or 2nd message, as they are usually caused by the earlier ones. Being short on coffee and contact solution, I stared at this for quite a while. Searching my ~100 line script, there was only one my declaration for each of these variables! [Calm down -- Perl isn't picking on you. Perl is doing the best it can, given the shoddy input you gave it. You must be doing something wrong -- think.] The scope hint started to sink in, so I went looking for missing }s and )s, as this is one of my frequent failings. I found a missing ) on an if conditional, and tried again. Now there were more my errors! Calming down somewhat (no, drugs were not involved, but thanks for asking), I decided to isolate sections of code to narrow down the search for the offending line(s). I prematurely ended a few blocks with }s, and deftly placed an __END__ to isolate the problem section: OK, I've narrowed it down to a few lines of code. Careful checking of all {} and () pairs (thank you for small miracles and smart editors), I found another lopsided if conditional. Wala! Problem solved! But wait...Why did perl report all of those my errors, and not something more appropriate to missing )s? It did, near the end: Moral: If the first error message doesn't help you find the cause, check through more of them. After all, Perl doesn't stop at the first error message because that may not be the cause of the error. Feel free to contribute your own D'oh moments from compiler message head scratching sessions. Brought to you by your local chapter of the Perl Error Message Society. -QM
Back to
Meditations
|
|