#!/local/bin/perl # Generate "word bingo" cards from existing word lists # # Copyright (c) 2000-2003 by Curtis C. Chen # require '/fir/mh/home/sparckl/cgi-bin/cgi-lib.pl'; #blah use lib '/fir/mh/home/sparckl/shell/Perl/lib/perl5/site_perl/5.6.1'; use Text::Template; #---------------------------------------------------------------------- #LOCATIONS #word lists $COMMON='COMMON'; $UNCOMMON='UNCOMMON'; $RARE='RARE'; $NAME='NAME'; #output template $OUTT='card.tmpl'; #---------------------------------------------------------------------- #VARIABLES @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 four lists open(COMMON,"<$COMMON") or die "$COMMON: $!"; while () { push (@common_words, $_); } open(UNCOMMON,"<$UNCOMMON") or die "$UNCOMMON: $!"; while () { push (@uncommon_words, $_); } open(RARE,"<$RARE") or die "$RARE: $!"; while () { push (@rare_words, $_); } open(NAME,"<$NAME") or die "$NAME: $!"; while () { push (@name_words, $_); } #randomize all four lists *in place* 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__