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

I've just started learning about Perl and everything about it seems so cool, the history, the culture, and what it means to people. I started reading "Learning Perl" (Second Ed.) and need some help. I'm on p 7 of the book (Guessing the Secret Password) and keep getting an error. I modified the sample code slightly and according to MY (flawed) assumption, everything looks alright and should work fine. Could someone take a look at this code?
#!/usr/bin/perl -w $secretword="llama"; print "Welcome. What is your name? "; $name= <STDIN>; chomp ($name); if ($name eq "Neil") { print "Yoooo wazzzzup, Neil! Right this way, man..."; } else { print "Hey, hold up. I'm going to need the secret password: "; $guess= <STDIN>; chomp ($guess); while ($guess ne $secretword) { Print "Wrong! Try again: "; $guess=<STDIN>; chomp ($guess); } }
Please excuse its blatant corniness ;)

Replies are listed 'Best First'.
Re: Newbie Help!
by turnstep (Parson) on Aug 07, 2000 at 03:19 UTC

    Remember to check your error messages carefully. The one you received probably had this in it:

    (Do you need to predeclare Print?)

    That "predeclare" line 9 times out of 10 means you made a typo. Perl in this case made a pretty darn good guess at what was wrong.

RE: Newbie Help!
by reptile (Monk) on Aug 07, 2000 at 02:38 UTC

    Well, this line:

    Print "Wrong! Try again: ";
    is wrong. It's print, all lower-case. I changed that and it ran just fine.

    local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }

Re: Newbie Help!
by tilly (Archbishop) on Aug 07, 2000 at 02:35 UTC
    2 things. First use the CODE tag when posting code. It makes indentation come through. Secondly Perl is case sensitive. Your Print is not the same as print.

    Cheers,
    Ben