#!/usr/bin/perl # Generate "word bingo" cards from existing word lists # # Copyright (c) 2000-2008 by Curtis C. Chen # #blah require '/home/ckloviii/cgi-bin/cgi-lib.pl'; #double blah use lib '/home/ckloviii/sparckl/shell/Perl/lib/perl5/site_perl/5.6.1'; use Text::Template; #---------------------------------------------------------------------- #LOCATIONS #word lists $SURETY = 'SURETY'; $COMMON='COMMON'; $UNCOMMON='UNCOMMON'; $RARE='RARE'; $NAME='NAMES'; #output template $OUTT='card.tmpl'; #---------------------------------------------------------------------- #VARIABLES @sure_things=(); @common_words=(); @uncommon_words=(); @rare_words=(); @name_words=(); #---------------------------------------------------------------------- #SUBROUTINES #shuffle( \@array ) : generate a random permutation of @array in place ##Fisher-Yates shuffle algorithm from Perl Cookbook, recipe 4.17## sub shuffle { my $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } } #---------------------------------------------------------------------- #MAIN PROGRAM #persuade browser to display print &PrintHeader; #read in all word lists... #but only take three-letter words or longer! open(SURETY,"<$SURETY") or die "$SURETY: $!"; while () { if ( /\w\w\w+/ ) { push (@sure_things, $_); } } open(COMMON,"<$COMMON") or die "$COMMON: $!"; while () { if ( /\w\w\w+/ ) { push (@common_words, $_); } } open(UNCOMMON,"<$UNCOMMON") or die "$UNCOMMON: $!"; while () { if ( /\w\w\w+/ ) { push (@uncommon_words, $_); } } open(RARE,"<$RARE") or die "$RARE: $!"; while () { if ( /\w\w\w+/ ) { push (@rare_words, $_); } } open(NAME,"<$NAME") or die "$NAME: $!"; while () { if ( /\w\w\w+/ ) { push (@name_words, $_); } } #randomize all word lists *in place* shuffle( \@sure_things ); shuffle( \@common_words ); shuffle( \@uncommon_words ); shuffle( \@rare_words ); shuffle( \@name_words ); #################### # RFE: also shuffle word locations on card (e.g., use same frequencies but # floating locations for each common, uncommon, name, etc.) #################### #DEBUG#foreach (@common_words) { print STDOUT $_; } #DEBUG#print (shift @common_words); #====================================================================== #web page template contains more code! $template = new Text::Template (TYPE => FILE, SOURCE => $OUTT); $text = $template->fill_in(); print $text; __END__