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):

C:\Perl\perl\BOD>perl -c bod_mask.pl "my" variable $rsp masks earlier declaration in same scope at bod_mask +.pl line 99. "my" variable $rsp_line masks earlier declaration in same scope at bod +_mask.pl line 99. "my" variable @bits masks earlier declaration in same scope at bod_mas +k.pl line 101. "my" variable $rsp masks earlier declaration in same scope at bod_mask +.pl line 101. "my" variable @bits masks earlier declaration in same scope at bod_mas +k.pl line 103. "my" variable $bit_index masks earlier declaration in same scope at bo +d_mask.pl line 103. "my" variable $time masks earlier declaration in same scope at bod_mas +k.pl line 105. "my" variable $space masks earlier declaration in same scope at bod_ma +sk.pl line 105. "my" variable @bits masks earlier declaration in same scope at bod_mas +k.pl line 105. syntax error at bod_mask.pl line 85, near ") (" Global symbol "$time" requires explicit package name at bod_mask.pl li +ne 85. Global symbol "$space" requires explicit package name at bod_mask.pl l +ine 85. Global symbol "$bits" requires explicit package name at bod_mask.pl li +ne 85. Global symbol "$bit_string" requires explicit package name at bod_mask +.pl line 86. syntax error at bod_mask.pl line 91, near ") {" syntax error at bod_mask.pl line 96, near "elsif" syntax error at bod_mask.pl line 106, near "}" bod_mask.pl had compilation errors.
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:

C:\Perl\perl\BOD>perl -c bod_mask.pl bod_mask.pl syntax OK
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:

syntax error at bod_mask.pl line 91, near ") {"
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
--
Quantum Mechanics: The dreams stuff is made of


In reply to Grokking Compile Error Messages by QM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.