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

[MacPerl] regarding Filehandle



Salutations-
I was working on the first chapter of the book. I really need to learn this for my job. I'm having some dificulty figuring out how to create a <WORDSLIST>. It's really great, because I copied the whole program down (correctly). I ran it in perl, but it doesn't look in the wordslist like it's supposed to and find all the appropriate passwords. Instead it returns the "password incorrect answer and the only way to make it answer correctly is to give the default answer or to be the one person that doesn't have to give a password. I  checked my syntax and it's OKAY. I made a new script and called it wordlist and then saved it, but it can never find it. I work on a mac os8 system. and I was really hoping that you could tell me where in my MacPerl files the WORDSLIST is suppoussed to go and do I just write the individual passwords without any other code or do I do something else? I've included an example of the code I've written so far
#!alexandria:Applications:MacPerl °:lib:CGI:perl -w

init_words();
print "What is your name?";
$name = <STDIN>;
chomp $name;
if ($name =~ /^ron\b/i) {	#okay to compare this way now, yes it matches
	print "Hello, Ron!It's nice to see you again\n";
}else {						#no it does not match
	print "Hello, $name\n";		#ordinary greeting, print "What is the secret word? ";
	$guess = <STDIN>;
	chomp ($guess);
	while (! good_word ($name, $guess))	{
		print "Wrong, $name try again. What is the secret word? ";
		$guess = <STDIN>;
		chomp ($guess);
	}
}
##subroutines from here down

sub init_words {
	open (WORDSLIST, "wordslist") ||
									die "can't open wordslist: $!";
	while ( defined ($name = <WORDSLIST>))	{
		chomp ($name);
		$word = <WORDSLIST>;
		chomp $word;
		$words {$name} = $word;
		close (WORDSLIST) ||	die "couldn't close wordslist: $!";
	}
}
	sub good_word {
	my ($somename,$someguess) = @_;     #this is to be saved for the greeting
$name =~ s/\W.*//;			#this gets rid of everything after the first word
$name=~ tr/A-Z/a-z/;		#lowercase everything;			$somename=~ s/\W.*//; #get rid of everything after the first word
	$somename=~ tr/A-Z/a-z/;	#lowercase everything
	if ($somename eq "ron") {	#this is so he won't need to guess
		return 1;				#return value is true
	} elsif	(($words{$somename} || "hello") eq $someguess)	{
		return 1;				#value is true again, remember this is the default value
	} else {
		return 0;				#return value is false
	}
}
Error Message
# can't open wordslist: No such file or directory.
File 'alexandria:Applications:MacPerl °:lib:CGI:system hello'; Line 23




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