Tutorials: Basic debugging checklist , brian's Guide to Solving Any Perl Problem

Lets try one of these tips

$ perl -c crates syntax error at crates line 7, near "foreach @line " crates had compilation errors. $ perl -Mdiagnostics -c crates syntax error at crates line 7, near "foreach @line " crates had compilation errors (#1) (F) Probably means you had a syntax error. Common reasons include +: A keyword is misspelled. A semicolon is missing. A comma is missing. An opening or closing parenthesis is missing. An opening or closing brace is missing. A closing quote is missing. Often there will be another error message associated with the synt +ax error giving more information. (Sometimes it helps to turn on -w. +) The error message itself often tells you where it was in the line +when it decided to give up. Sometimes the actual error is several toke +ns before this, because Perl is good at understanding random input. Occasionally the line number may be misleading, and once in a blue + moon the only way to figure out what's triggering the error is to call perl -c repeatedly, chopping away half the program each time to se +e if the error went away. Sort of the cybernetic version of S<20 questions>. Uncaught exception from user code: syntax error at crates line 7, near "foreach @line " crates had compilation errors. at crates line 10.

Hmm, not so helpful. Ok, next check perlintro and perlsyn, specifically look for instances of foreach

$ perldoc perlintro | grep foreach the more friendly list scanning "foreach" loop. foreach foreach (@array) { print $list[$_] foreach 0 .. $max; foreach my $key (keys %hash) { $ perldoc perlsyn | grep foreach foreach LIST The "foreach" modifier is an iterator: it executes the statement o +nce print "Hello $_!\n" foreach qw(world Dolly nurse); LABEL foreach VAR (LIST) BLOCK LABEL foreach VAR (LIST) BLOCK continue BLOCK The "foreach" loop iterates over a normal list value and sets the loop. This implicit localization occurs *only* in a "foreach" loop +. The "foreach" keyword is actually a synonym for the "for" keyword, + so you can use "foreach" for readability or "for" for brevity. (Or be +cause "foreach" loop index variable is an implicit alias for each item i +n the If any part of LIST is an array, "foreach" will get very confused +if you "foreach" probably won't do what you expect if VAR is a tied or ot +her foreach $item (split(/:[\\\n:]*/, $ENV{TERMCAP})) { Perl executes a "foreach" statement more rapidly than it would the Instead of using "given()", you can use a "foreach()" loop. For ex +ample, requires initialization, such as a subroutine or a "foreach" loop. + It

ok, I don't see any "foreach @" uses, so checking http://perldoc.perl.org/perlsyn.html#Foreach-Loops is see lots of examples, but no "foreach @"

That has to be the syntax error, changing that to "foreach $line ($a)"

$ perl -c crates Global symbol "$line" requires explicit package name at crates line 7. crates had compilation errors.

Right, that is strict catching a typo for me, I should write  foreach my $line ($a)

$ perl -c crates crates syntax OK

Great , syntax error resolved, next, some other things you should know

perlvar#$a is a special variable, don't use it

Don't use single argument form of open, use the 3 argument form

using perlvar#@ARGV is better thanusing  <STDIN>

$a is a filehandle, but you don't try to readline from it like you do from STDIN

I highly recommend perlintro, http://learn.perl.org/books/beginning-perl/, http://perl-tutorial.org/, Modern Perl


In reply to Re: I am geting an unhelpful error message. Not sure how to debug it. by Anonymous Monk
in thread I am geting an unhelpful error message. Not sure how to debug it. by Socrates440

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.