NEWBIE:unexplained syntax error

M

Michiel

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
 
G

Gunnar Hjalmarsson

Michiel said:
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?
 
B

Barry Kimelman

[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top