in reply to I am geting an unhelpful error message. Not sure how to debug it.

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

Replies are listed 'Best First'.
Re^2: I am geting an unhelpful error message. Not sure how to debug it.
by stevieb (Canon) on Jun 15, 2012 at 04:35 UTC

    This is a spectacular post AnonyMonk. At first I wished I could have upvoted a name, but I like your style... a lot.