[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] New MacPerl user needs help!



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch

Hello list.  I'm Jared, and I'm very new to MacPerl.  I'm somewhat new to 
Perl as well.  I have a dilemma.  I'm using a book, "Learning Perl" by 
O'Reilly and Associoates to learn how to script.  One of the sample 
programs included is not working for me in MacPerl.  It's basically just 
a simple little password program, but here's what it looks like, in a 
shortened form:


&init_words;
print "What is your name? ";
$name = <STDIN>;
chop($name);
if ($name eq "Jared") {
			print "Hello, Jared.  How nice to see you.\n";
} else {
			print "Hello, $name.  What is the secret word? ";
			$guess = <STDIN>;
			chop($guess);
			while (! &good_word($name,$guess)) {
						print "Wrong, try again.  What is the secret word? ";
						$guess = <STDIN>;
						chop($guess);
			}
}
sub good_word {
			local($someName,$someGuess) = @_;
			$someName =~ s/\W.*//;
			$someName =~ tr/A-Z/a-z/;
			if ($someName eq "jared") {
						1;
			} elsif (($words{$someName}) eq $someGuess) {
						1;
			} elsif ("default" eq $someGuess) {
						1;
			} else {
						0;
			}
}
sub init_words {
			open(WORDSLIST, "wordslist");
			while ($name = <WORDSLIST>) {
						chop($name);
						$word = <WORDSLIST>;
						chop($word);
						$words{$name} = $word;
			}
			close(WORDSLIST);
}



Here's the textfile, which I appropriately named "wordslist", without the 
quotes of course:

sherri
kitten
jason
hotrod


This textfile has strings that are usernames and passwords alternating.

This script is not working for me.  Can somebody please tell me why?  I 
know that it is opening the file.  But it is not reading any of the data 
from it.  The "default" password works fine.  I'm stumped.  Please reply 
to me privately at:  themiles@swbell.net

TIA,
Jared