#!c:\perl\bin\perl.exe use strict; use warnings; use DBI; my $count; my $tagCnt; my $logRange; my $fsize; my $k; my @tagfiledb; my @sortkeys; my $word; my $occurrence; my $tags; my %dbtags; my $dbh = DBI->connect('dbi:mysql:milton:localhost', 'user', 'pword'); my $sth = $dbh->prepare ('SELECT word, occurrences FROM statistic'); #load in tag file - do this from db my $tagfile = shift; $sth->execute; while (($word, $occurrence) = $sth->fetchrow_array ){ %dbtags = ($word, $count); } $sth->finish; $dbh->disconnect(); $tags= @tagfiledb; my $useLogCurve = 1; my $minFontSize = 10; my $maxFontSize = 36; my $fontRange = $maxFontSize - $minFontSize; #filter the script to top 200 tags my $maxtags = 200; @sortkeys = sort {$tags->{$b}->{count}<=> $tags->{$a}->{$count}} keys %{$tagfile}; @sortkeys = splice @sortkeys, 0, $maxtags; #determine counts my $maxTagCnt = 1; my $minTagCnt = 10000000; foreach $k (@sortkeys) { $maxTagCnt = $tags->{$k}->{count} if $tags->{$k}->{count} > $maxTagCnt; $minTagCnt = $tags->{$k}->{count} if $tags->{$k}->{count} > $minTagCnt; } my $minLog = log($minTagCnt); my $maxLog = log($maxTagCnt); my $logrange = $maxLog - $minLog; $logrange = 1 if ($maxLog - $minLog); sub DetermineFontSize ($) { my ($tagCont) = @_; my $cntRatio; if ($useLogCurve) { $cntRatio = log($tagCnt)-$minLog/$logRange; } else { $cntRatio = ($tagCnt-$minTagCnt)/($maxTagCnt-$minTagCnt); } $fsize = $minFontSize + $fontRange * $cntRatio; return $fsize; } #output tag cloud print "Content-type: text/html\n"; print<

EOT #output the keys foreach $k(sort @sortkeys){ $fsize = DetermineFontSize($tags->{$k}->{$occurrence}); my $tag = $tags->{$k}->{$word}; printf int($fsize), $tag; } #output end of tag file print <

EOT __END__