#!/usr/bin/perl # # choose_words.plx # # choose 5 words at random from a list my $wordlist = "data/wordlist"; my $current = "beads_current.html"; my $past = "beads_past.html"; ### For testing ## my $current = "/tmp/beads_current.html"; ## my $past = "/tmp/beads_past.html"; my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @wdays = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); my $dictcom = '>", $past) or die "$0: cannot open past word set: $!\n"; ### Update the Past Words History file # get the most currently published word set { local $/ = ''; $c_list = ; } close(CUR); # remove level 4 header tags so words are no longer bolded # and reduce level 3 headers to level 4 $c_list =~ s/

//g; $c_list =~ s/<\/H4>/
/g; $c_list =~ s/H3>/H4>/g; # append the current word set to the list of past word sets print PST $c_list; print PST "\n"; close(PST); # Now select a new current word set # open and read in the dictionary (wordlist) open(FH, "<", $wordlist) or die "$0: cannot open wordlist: $!\n"; @wordset = ; $numwords = $#wordset + 1; close(FH); # Choose 5 words at random, no dups for ($i=1; $i<=$#wordset; $i++) { $choice = int(rand($numwords)) + 1; my $word = $wordset[$choice]; chomp($word); unless ( exists ($words{$word}) ) { $words{$word} = 1; last if (++$wordcount == $maxcount); } } # preserve the current word set rename ($current, ${current} . '_prev'); # reopen the current bead file, this time for editing open(CUR, ">", $current) or die "$0: cannot open current beads file: $!\n"; # Insert today's word set printf CUR "

Word Beads for %s %2d, %4d

\n", $months[$month], $day, $year; print CUR "
\n"; foreach my $key (keys(%words)) { printf CUR "%s?q=%s\" target=\"_blank\"\n>", $dictcom, $key; print CUR "

", ucfirst($key), "

\n"; } print CUR "
\n"; close(CUR); }