#!/usr/bin/perl
&init_words;
print "What is your name? ";
$name=<STDIN>;
chop($name);
if ($name =~ /^randal\b/i) {print "Hello, Randal! How good... \n";}
else 
{ 
	print "Hello, $name!\n";
	print "What is the secret word? ";
	$guess=<STDIN>;
	chop($guess);
	while (! &good_word($name,$guess))
	{
		print "Wrong, try again... ";
		$guess=<STDIN>;
		chop($guess);
	}
}

sub init_words
{
	open(WORDSLIST,"wordslist");
	while ($name=<WORDSLIST>)
	{
		chop($name);
		$word=<WORDSLIST>;
		chop($word);
		$words{$name}=$word;
	}
	close(WORDSLIST);
}

sub good_word
{
	local($somename,$someguess)=@_;
	$name =~ s/\W.*//;
	$name =~ tr/A-Z/a-z/;
	if ($somename eq "randal") {1;}
	elsif (($words{$somename} || "groucho") eq $someguess) {1;}
	else {0;}
}