Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Simple syntax error?

by Anonymous Monk
on Jul 13, 2007 at 23:01 UTC ( [id://626542]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

It must be simple but I can't find it. I've been playing with code far too long today.
While($#letters + 1 > 5) { print "\n\nYou can't guess more than 5 letters! Try again."; print "\n\nEnter 5 letters: "; $letters = <STDIN>; chomp($letters); }
It errors with:
syntax error at .. line 39, near ") {" syntax error at .. line 45, near "}" Execution of .. aborted due to compilation errors.

Replies are listed 'Best First'.
Re: Simple syntax error?
by runrig (Abbot) on Jul 13, 2007 at 23:44 UTC
    letters is not an array. It is a string. The $#letters syntax is for arrays (it returns the last index of the array...or one less than the length of the array). Perhaps you want to use the length function. Are you using strict? Though the capital "W" in the while is your syntax error, as has already been pointed out.
Re: Simple syntax error?
by sulfericacid (Deacon) on Jul 13, 2007 at 23:02 UTC
    Look closely to the first line of your snippet. Remember, case matters.

    Hope this helps.



    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
Re: Simple syntax error?
by GrandFather (Saint) on Jul 13, 2007 at 23:40 UTC

    Not the problem you were asking about, but: $#letters + 1 is equivelent to @letters in a scalar context and the latter is probably a little clearer.


    DWIM is Perl's answer to Gödel
Re: Simple syntax error?
by FunkyMonk (Chancellor) on Jul 13, 2007 at 23:04 UTC
    While($#letters + 1 > 5)
    Capital W?
Re: Simple syntax error?
by Anonymous Monk on Jul 14, 2007 at 08:06 UTC
    While unrelated to your syntax error, the following line is equivalent to the last two in your code. I always hate to use two lines when one will do.

    chomp( $letters = <STDIN> );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://626542]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 18:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found