Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Typing Tutor

by spacewarp (Pilgrim)
on Mar 25, 2001 at 08:54 UTC ( #66956=CUFP: print w/replies, xml ) Need Help??

I got a Dvorak keyboard for Christmas this year. It came with a typing tutor, but it didn't give me the type of real-world practice that I needed. So I wrote this.

The "words" file is just linux's dict file, and the quotes.txt file is a list of about 5000 one-line jokes.
In addition to verifying the correctness of your keyboarding, it also times you, and gives you a rough count of your typing speed.

################################################ # # 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 <<EOA; Typing Tutor -=-=-=-=-=-=-=-=-=-=- 1) Words 2) Quotes/Jokes 3) Exit EOA ; print "What'll it be? "; chomp( $choice = <STDIN> ); 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 <WORDS>; chomp $line; print "Word: $line\n"; print "Retype: "; chomp( $typed = <STDIN> ); 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 <QUOTES>; 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 = <STDIN> ); $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); } }

Replies are listed 'Best First'.
Re: Typing Tutor
by dusk (Friar) on Mar 26, 2001 at 01:25 UTC
    Nice idea, just a few words of criticism:

  • use strict;
  • use Time::Local;
  • srand is no longer necessary in perl version's > 5.005 (correct me if I'm inaccurate)

    Happy Hacking! :)

    update: srand is no longer necessary in perl version's > 5.004. Apologies for any confusion :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://66956]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2022-01-20 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?