Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-28 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found