yolanda/trunk/tagcloud.pl

34 lines
717 B
Perl
Raw Normal View History

#!/usr/bin/perl -w
use DBI;
use Data::Dumper::Simple;
$database = 'yolanda';
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
$sth = $dbh->prepare("select subject from videos");
$sth->execute();
while(($subject) = $sth->fetchrow_array())
{
@subject = split(',', $subject);
foreach my $val (@subject)
{
$val =~ s/^\s*(.*?)\s*$/$1/;
%hash->{$val}++;
}
}
$sth->finish();
@sorted = sort {$hash{$b} cmp $hash{$a}} keys %hash;
$dbh->do("delete from tagcloud");
$sth = $dbh->prepare("insert into tagcloud (text, count) values (?, ?)");
for($i=0;$i<20 and $i<=$#sorted;$i++)
{
$sth->execute( $sorted[$i], %hash->{$sorted[$i]} );
}