I am new to Perl, but I used this as a learning exercise (very little of this is original code. Ref: Learning Perl, and Perlmonks). Basically a game to see how fast you can type, with an output of stats at the end.

The dictionary is hopefully on everyone's system, it doesn't exactly have real words though...

Just run the program on Terminal.

If you don't have List::Utils, just take that line out, and the declaration line that uses shuffle, and replace @shuffled_words with @words in the foreach loop. If you don't have that dictionary... find another text file and use appropriately, or just type up your own(not recommended). ENJOY:

#! usr/bin/perl use strict; use warnings; # -- TYPING SPEED GAME -- # #OPTIONAL (but currently implemented): use List::Util 'shuffle'; #Or use substitute/ don't sort. # WORD LIST: #my @words = qw{ fred barney pebbles dino wilma betty }; #Could get different list of words from another file or, like above, j +ust typing them in. my $file = '/usr/share/dict/words'; open( FIN, '<', $file ) or die("$file"); my @words = map { chomp; $_ } <FIN>; close FIN; #sort words; randomly my @shuffled_words = shuffle(@words); #Instructions: print "This is a game to test how fast you can type these 'words'.\nThe game + ends when you get 5 errors or reach the end of the dictionary\n"; print "You can exit by pressing ctrl-c or command .\n"; print "\n First choose the MAXIMUM number letters you want in the w +ords\n"; print " Then type the word that shows up:\n"; print " After typing, press Enter.\n"; print " Type Enter without any entry to skip the word\n"; print " Don't forget: Case Matters!\n"; #Begin: #Max letters print "\nWhat maximum number of letters do you want?\n\n"; chomp( my $max_length = <> ); #Should check if it's a number? if ($max +_length =~ /\D/) {try again} my $errors = 0; #time start my $starttime = time(); #If don't want sort, use `@words` in loop: foreach (@shuffled_words) { #Stop the Game if ( $errors >= 5 ) { print "Game Over. Too many errors!\n\n"; last; } #Main Type Game: ## redo comes here ## unless ( length $_ >= $max_length ) { print "\nType the word\n '$_': "; chomp( my $try = <STDIN> ); next if ( $try eq '' ); if ( $try ne $_ ) { print "Sorry - That's not right.\n\n"; $errors++; redo; # jump back up to the top of the loop } } } #end time my $endtime = time(); my $totaltime = $endtime - $starttime; #Post game Report print "Game Stats:\n"; print "Max word length: $max_length\n"; print "Your current time is $totaltime s, with $errors errors.\n"; print "\nTry again. You didn't get all the words.\n\n"; #Winner?! print "Wow! You went through the entire dictionary! Try a longer word leng +th!\n\n" unless ( $errors eq 5 ); #Future: #Could implement saving highscores by sending to a file... and testing + against it's contents #Add count for skips #For output: use Term::ANSIColor;

Feel free to add suggestions or comments. This is a learning experience after all!


In reply to Speed Typing Game by jonc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.