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

This doesn't work It gives me the warning "Use of uninitialized value at test.pl line 16, <STDIN> chunk 1."
@words=qw( fred camel barney llama betty alpaca wilma alpaca ); print "What is your name?\n"; $name=<STDIN>; chomp ($name); if ($name eq "Randal") { print "Hello, Randal! Welcome!\n" } else { print "Hello $name.\n"; $secretword=$words{$name}; # use {} for hash if ($secretword eq ""){ # gives me an error around here $secretword="stupid"; #default secret word } print "What is the secret word?"; $guess =<STDIN>; chomp($guess); while ($guess ne $secretword){ print "Wrong, try again.\n"; $guess=<STDIN>; chomp ($guess); } }
Help please! alvarr3

Replies are listed 'Best First'.
Re: Newbie needs help
by chumley (Sexton) on Mar 25, 2001 at 10:24 UTC

    Change '@words' in the first line to '%words'. I did this with your code and it started working.

    It's a common mistake, one I make all the time (also with arrays) so I keep a copy of the Perl CD bookshelf handy whenever I'm coding.

    Chumley
      I wondered if this was an errata or a typo and I thought it might be worth noting that you can find the errata for all O'Reilly books on their web site, here for the Llama book and this example is in the sample chapter.
      -w and use strict will pick up most of those typos for you :)

      --
      my $chainsaw = 'Perl';

Re: NEwbie needs help
by Hero Zzyzzx (Curate) on Mar 25, 2001 at 10:46 UTC

    Please see my fuller answer/advice here.