<P><FONT SIZE=-1>I am a beginner in MacPerl. To be very honest</FONT> <BR><FONT SIZE=-1>it is my first try at learning a language. I have</FONT> <BR><FONT SIZE=-1>encountered some problems. Can anyone be</FONT> <BR><FONT SIZE=-1>of some help?</FONT> <P><FONT SIZE=-1>I have transcribed below a programme from Learning</FONT> <BR><FONT SIZE=-1>Perl by Randal Shwartz and Tom Christiansen</FONT> <BR><FONT SIZE=-1>(Chapter 1) which has come to confuse me in the end.</FONT> <BR><FONT SIZE=-1>As there is no explicit instructions given, I am unable</FONT> <BR><FONT SIZE=-1>to configure a secret-words list to make the programme</FONT> <BR><FONT SIZE=-1>work. The lesson in the end of the Chapter 1 says:</FONT> <P><FONT SIZE=-1> 1. Type in the example programs and get them to</FONT> <BR><FONT SIZE=-1> work. (You will need to create a secret-word lists</FONT> <BR><FONT SIZE=-1> as well). Consult your local Perl guru if you</FONT> <BR><FONT SIZE=-1> need assistance.</FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> I am sorry to say there is no Perl guru that I know</FONT> <BR><FONT SIZE=-1> of in India. I am sending this to the MacPerl Mailing</FONT> <BR><FONT SIZE=-1> list to have someone answer my question.</FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> thanks in advance</FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> Amitava Basu</FONT> <BR><FONT SIZE=-1> </FONT> <BR> <P><FONT SIZE=-1>#!/usr/bin/perl</FONT> <BR><FONT SIZE=-1>init_words ();</FONT> <BR><FONT SIZE=-1>print "What is your name? ";</FONT> <BR><FONT SIZE=-1>$name = <STDIN>;</FONT> <BR><FONT SIZE=-1>chomp ($name);</FONT> <BR><FONT SIZE=-1>if ($name =~/^randal\b/i) {</FONT> <BR><FONT SIZE=-1> print "Hello, Randal, How good of you!/n";</FONT> <BR><FONT SIZE=-1> }else{</FONT> <BR><FONT SIZE=-1> print "hello, $name!/n";</FONT> <BR><FONT SIZE=-1> print "What is the secret word?";</FONT> <BR><FONT SIZE=-1> $guess = <STDIN>;</FONT> <BR><FONT SIZE=-1> chomp ($guess);</FONT> <BR><FONT SIZE=-1> while (! good_word ($name, $guess)) {</FONT> <BR><FONT SIZE=-1> print "Wrong, Try Again!!";</FONT> <BR><FONT SIZE=-1> $guess = <STDIN>;</FONT> <BR><FONT SIZE=-1> chomp ($guess);</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> dbmopen (%last_good, "lastdb", 0666);</FONT> <BR><FONT SIZE=-1> $last_good {$name} = time;</FONT> <BR><FONT SIZE=-1> dbmclose (%last_good);</FONT> <BR><FONT SIZE=-1> sub init_words {</FONT> <BR><FONT SIZE=-1> while ($filename = <*.secret>) {</FONT> <BR><FONT SIZE=-1> open (WORDSLIST, $filename) ||</FONT> <BR><FONT SIZE=-1> die "can't open $filename: $!";</FONT> <BR><FONT SIZE=-1> if (-M WORDSLIST < 7.0) {</FONT> <BR><FONT SIZE=-1> while ($name = <WORDSLIST>) {</FONT> <BR><FONT SIZE=-1> chomp ($name);</FONT> <BR><FONT SIZE=-1> $word = <WORDSLIST>;</FONT> <BR><FONT SIZE=-1> chomp ($word);</FONT> <BR><FONT SIZE=-1> $words {$name} = $word;</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> } else {</FONT> <BR><FONT SIZE=-1> rename ($filename, "$filename.old") ||</FONT> <BR><FONT SIZE=-1> die "can't rename $filename.old: $!";</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> close WORDSLIST;</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> sub good_word {</FONT> <BR><FONT SIZE=-1> my ($somename, $someguess) = @_;</FONT> <BR><FONT SIZE=-1> $somename =~ s/\W.*//;</FONT> <BR><FONT SIZE=-1> $somename =~ tr/A-Z/a-z/;</FONT> <BR><FONT SIZE=-1> if ($somename eq "randal") {</FONT> <BR><FONT SIZE=-1> return 1;</FONT> <BR><FONT SIZE=-1> } elsif (($words {$somename} || "groucho") eq $someguess) {</FONT> <BR><FONT SIZE=-1> return 1;</FONT> <BR><FONT SIZE=-1> } else {</FONT> <BR><FONT SIZE=-1> open (MAIL, "|mail YOUR_ADDRESS_HERE");</FONT> <BR><FONT SIZE=-1> print MAIL "bad news: $somename guessed $someguess \n";</FONT> <BR><FONT SIZE=-1> close MAIL;</FONT> <BR><FONT SIZE=-1> return 0;</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> }</FONT> <P><FONT SIZE=-1> #!/usr/bin/perl</FONT> <BR><FONT SIZE=-1> while ($filename = <*.secret>) {</FONT> <BR><FONT SIZE=-1> open (WORDSLIST, $filename) ||</FONT> <BR><FONT SIZE=-1> die "can't open $filename: $!";</FONT> <BR><FONT SIZE=-1> if (M WORDSLIST < 7.0) {</FONT> <BR><FONT SIZE=-1> while ($name = <WORDSLIST>) {</FONT> <BR><FONT SIZE=-1> chomp ($name);</FONT> <BR><FONT SIZE=-1> $word = <WORDSLIST>;</FONT> <BR><FONT SIZE=-1> chomp ($word);</FONT> <BR><FONT SIZE=-1> write;</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> close (WORDSLIST);</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> format STDOUT =</FONT> <BR><FONT SIZE=-1> @<<<<<<<<<<<<<<< @<<<<<<<<< @<<<<<<<<<<<</FONT> <BR><FONT SIZE=-1> $filename, $name, $word</FONT> <BR><FONT SIZE=-1> .</FONT> <BR><FONT SIZE=-1> format STDOUT_TOP =</FONT> <BR><FONT SIZE=-1> Page @<<</FONT> <BR><FONT SIZE=-1> $%</FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> Filename Name Word</FONT> <BR><FONT SIZE=-1> ============== ========== ===========</FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> #!/usr/bin/perl</FONT> <BR><FONT SIZE=-1> dbmopen (%last_good, "lastdb", 0666),;</FONT> <BR><FONT SIZE=-1> foreach $name (sort keys %last_good) {</FONT> <BR><FONT SIZE=-1> $when = $last_good {$name};</FONT> <BR><FONT SIZE=-1> $hours = (time - $when) / 3600;</FONT> <BR><FONT SIZE=-1> write;</FONT> <BR><FONT SIZE=-1> }</FONT> <BR><FONT SIZE=-1> </FONT> <BR><FONT SIZE=-1> format STDOUT =</FONT> <BR><FONT SIZE=-1> User @<<<<<<<<<<<<<: last correct guess was @<<< hours ago</FONT> <BR><FONT SIZE=-1> $name, $hours</FONT> <BR><FONT SIZE=-1> .</FONT></HTML> </html>