in reply to Re: Uninitialized value ?
in thread Uninitialized value ?
It now contains four elements with the names of famous actors as keys.%words = qw ( fred camel barney llama betty alpaca wilma alpaca );
If the user enters one of the keys, everything will be fine, because e.g. $words{fred} is defined, so $secretword will get the value 'camel'.
If the user enters something, that is not in the list of keys, e.g. 'busunsl', then $words{busunsl} is not defined.
And $secretword will become undef.
And you check for an undef value with defined.
You wanted to fill something into $secretword if there was nothing in it, that is, if it is undef.
So your if-statement has to be:
if (! defined $secretword) {
With the ! meaning 'not'.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Uninitialized value ?
by Cine (Friar) on Aug 20, 2001 at 17:55 UTC | |
by busunsl (Vicar) on Aug 20, 2001 at 17:57 UTC | |
by All0uette (Acolyte) on Aug 21, 2001 at 19:54 UTC | |
by Cine (Friar) on Aug 21, 2001 at 21:01 UTC |