NEWBIE:unexplained syntax error

Discussion in 'Perl' started by Michiel, Sep 9, 2004.

  1. Michiel

    Michiel Guest

    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
     
    Michiel, Sep 9, 2004
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Sep 9, 2004
    #2
    1. Advertising

  3. [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
    >
     
    Barry Kimelman, Sep 10, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marty Cruise

    Unexplained Instance Error

    Marty Cruise, Jul 3, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    407
    David Waz..
    Jul 3, 2003
  2. Replies:
    2
    Views:
    482
  3. Nathan Sokalski

    Unexplained error when databinding

    Nathan Sokalski, Aug 25, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    2,190
    John Horst
    Aug 26, 2005
  4. =?Utf-8?B?am9uZWZlcg==?=

    Sudden unexplained IE validation error

    =?Utf-8?B?am9uZWZlcg==?=, Feb 5, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    375
    =?Utf-8?B?am9uZWZlcg==?=
    Feb 5, 2007
  5. Nathan Sokalski

    Unexplained error when databinding

    Nathan Sokalski, Aug 25, 2005, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    175
Loading...

Share This Page