################################################ # # Typing Tutor # # Throws up random words or quotes, # and then checks the re-typing of them. # # v0.1 by Jeremy Gross, jeremy@cwes.net # ################################################ use Time::local; while (1) { print < ); if ( $choice == 1 ) { print "\n\n\n"; Words(); } if ( $choice == 2 ) { print "\n\n\n"; Quotes(); } if ( $choice == 3 ) { exit; } } sub Words { MAIN: while (1) { open(WORDS, "words.txt") or print "Couldn't open word file: $!"; srand; rand($.) < 1 && ($line = $_) while ; chomp $line; print "Word: $line\n"; print "Retype: "; chomp( $typed = ); if ( $typed eq "." ) { last MAIN; } elsif ( $typed eq $line ) { print "Good!\n\n"; } else { print "WRONG!!!\n\n"; push (@wrong, $line); } close(WORDS); } } sub Quotes { $totalsecs = 0; $totalwords = 0; $totallines = 0; MAIN: while (1) { open(QUOTES, "quotes.txt") or print "Couldn't open quotes file: $!"; srand; rand($.) < 1 && ($line = $_) while ; chomp $line; $time1 = localtime; @fields1 = split(/\s+/, $time1); # print "$fields1[3]\n"; ($hour,$min1,$sec1) = split(/:/, $fields1[3]); print "Word: $line\n"; print "Retype: "; chomp( $typed = ); $time2 = localtime; # print "$fields2[3]\n"; @fields2 = split(/\s+/, $time2); ($hour,$min2,$sec2) = split(/:/, $fields2[3]); $sec1 += $min1 * 60; $sec2 += $min2 * 60; $SEC = $sec2 - $sec1; if ( $typed eq "." ) { last MAIN; } elsif ( $typed eq $line ) { print "Good!\n"; $totalsecs += $SEC; @temp = split(/ /, $typed); $totalwords += scalar @temp; $wpm = ($totalwords / ($totalsecs / 60)); print "Time: $SEC seconds Average: $wpm Words/Minute\n\n"; } else { print "WRONG!!!\n"; $totalsecs += $SEC; @temp = split(/ /, $typed); $totalwords += scalar @temp; $wpm = ($totalwords / ($totalsecs / 60)); print "Time: $MIN:$SEC Average: $wpm Words/Minute\n\n"; push (@wrong, $line); } close(QUOTES); } }