Often or maybe even most often with syntax errors, the line that is complained about occurs after the actual error because the compiler doesn't realize that something is wrong until it sees something else that it doesn't understand. In complex cases, this "complained about line" could be many lines past the "real error line".

I see the error right away, but say, you don't. Put __END__ right before the complained about line and see if you still get the error. If you still don't see then move the __END__ statement up. Perhaps in this case to below the first "print". That will work. Then you know that the "real error" is between those two points. Rinse, Repeat.

The key tip here is that starting in column 1, put __END__ and that stops the compilation process and runs the code to that point. Often you will see posts here where there is an END statement and then an example printout follows. This is an easy way to put all of the info into a single .pl post.

I very seldom write the whole program before running it. Write code, run code, debug, write more code,... Often I find some mistake early that affects how I write the rest of the code. That's true in assembly, Perl, C or whatever.


In reply to Re: syntax error at example.pl line 1 by Marshall
in thread syntax error at example.pl line 1 by reichktr

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.