Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > NEWBIE:unexplained syntax error

Reply
Thread Tools

NEWBIE:unexplained syntax error

 
 
Michiel
Guest
Posts: n/a
 
      09-09-2004
Hi. I am new to perl, working through the (so far excellent) book "Learning
Perl" by O'Reilly. So far so good, but now I run into smth I can't grasp.
When doing excercise 2 of chap.2, it won't compile, nomatter what I try.
Anyone see the error? I tried typing in the solution at the end of the book
and it gives the same error. The error is:

syntax error at ch2exc2.pl line 4, near "$COUNT("
Execution of ch2exc2.pl aborted due to compilation errors.

Here is the code:

#!perl
print "Enter seperate words, divided with (return):\n "; chomp(@INPUT =
<STDIN>);
foreach $WORD (@INPUT) {
$COUNT($WORD)++;
}
print %COUNT

Regards,
Michiel
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-09-2004
Michiel wrote:
> syntax error at ch2exc2.pl line 4, near "$COUNT("
> Execution of ch2exc2.pl aborted due to compilation errors.
>
> Here is the code:
>
> #!perl
> print "Enter seperate words, divided with (return):\n "; chomp(@INPUT =
> <STDIN>);
> foreach $WORD (@INPUT) {
> $COUNT($WORD)++;

----------------^-----^

You are using parentheses instead of braces.

Doesn't "Learning Perl" say anything about strictures and warnings?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Barry Kimelman
Guest
Posts: n/a
 
      09-10-2004
[This followup was posted to comp.lang.perl]

While wandering through cyberspace on 09 Sep 2004 21:05:46 GMT Michiel
said :
> Hi. I am new to perl, working through the (so far excellent) book "Learning
> Perl" by O'Reilly. So far so good, but now I run into smth I can't grasp.
> When doing excercise 2 of chap.2, it won't compile, nomatter what I try.
> Anyone see the error? I tried typing in the solution at the end of the book
> and it gives the same error. The error is:
>
> syntax error at ch2exc2.pl line 4, near "$COUNT("
> Execution of ch2exc2.pl aborted due to compilation errors.
>
> Here is the code:
>
> #!perl
> print "Enter seperate words, divided with (return):\n "; chomp(@INPUT =
> <STDIN>);
> foreach $WORD (@INPUT) {
> $COUNT($WORD)++;


$COUNT{$WORD}++; # you should have used braces here
> }
> print %COUNT
>
> Regards,
> Michiel
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM
Complier error!! error C2059: syntax error : '(' Balaji C++ 3 12-03-2004 11:19 PM



Advertisments