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

[MacPerl] newbie questions about Macperl



Hi List, I've got some newbie questions.


I've been working my way through the "learning perl" book using macperl and
have typed in an example in the 1st chapter; here it is.

#!perl-w
#
init_words();
print "What is your name? ";
$name = <STDIN>;
chomp $name;

if ($name =~ /^phil\b/i) {
    print "$name, how nice that you are here!\n";
} else {
    print "Hello $name!\n";
    print "What is the secret word? ";
    $guess = <STDIN>;
    chomp $guess;
    while (! good_word($name, $guess)) {
        print "Wrong, try again. What is the secret word? ";
        $guess = <STDIN>;
        chomp $guess;
    }
}

sub good_word {
	my ($somename, $someguess) = @_;
	$somename =~ s/\W.*//;
	$somename =~ tr/A-Z/a-z/;
	if ($name eq "phil") {
	    return 1;
	}
	elsif (($words{$somename} || "duck" ) eq $someguess) {
	    return 1;
	} else{
	    #open MAIL, "|mail phil.calvert@csun.edu";
	   # print MAIL "Bad news: $someone guessed $someguess\n";
	   # close MAIL;
	   print "mail would be sent here if I knew how \n";

	    return 0;
	}
}
sub init_words {
    open (WORDSLIST, "wordslist") || die "can't open word list: $!";
    if (-M WORDSLIST >= 7.0) {
        die "Sorry, the wordslist is older than seven days.";
    }
    while ($name = <WORDSLIST>) {
        chomp ($name);
        $word = <WORDSLIST>;
        chomp ($word);
        $words{$name} = $word;
    }
    close (WORDSLIST) || die "couldn't close word list: $!";
}

And here's the file "wordslist"

fred
camel
barney
llama
betty
alpaca
wilma
alpaca

My 1st question is, If I enter "fred" for the  name and "camel" for the guess
everthing is ok, when I enter a name that is not on in the wordslist and
"duck" for the guess everthing works *but* when I enter "fred" as the name
and "duck" as the guess the script still won't let me out of the while
loop. Why is that?

2nd q. How would I send mail on a mac?

And the final question; is there a digest version of this mailing list?

Thanks,


-
Phil Calvert--Faculty/Staff at CSUN Music Department

Voice (818) 677-3156
FAX (818) 677-5876
E-Mail phil.calvert@csun.edu



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org