use Tie::DBI;
use List::Compare;
tie %h,'Tie::DBI',{db => 'mysql:db',
table => 'table',
key => 'k',
user => 'root',
password => 'rootpass',
CLOBBER => 1};
%day = ('the' => '1', 'tuesday' => '2', 'wednesday' => '3');
$lc = List::Compare->new([keys %day],[keys %h]);
@intersections = $lc->get_intersection;
foreach $intersection (@intersections) {
print $intersection, "\n";
print $h{$intersection}{value}, "\n";
}
exit;
####
my %count;
#tie hash to the MySQL DB
tie my %h,'Tie::DBI',{db => 'mysql:db',
table => 'table',
key => 'k',
user => 'root',
password => 'rootpass',
CLOBBER => 1};
#split @titles by word, then to-lower, then remv special chars
my @intersections;
my $lc;
foreach my $title (@titles) {
my @words = split(" ", $title);
foreach my $word (@words) {
$word =~ tr/A-Z/a-z/;
$word =~ s/[^a-zA-Z0-9]*//g;
$count{$word}++;
print $word, "\n";
}
}
$lc = List::Compare->new([keys %count],[keys %h]);
@intersections = $lc->get_intersection;
foreach my $intersection (@intersections) {
print $intersection, "\n";
print $h{$intersection}{value}, "\n";
}
####
print $h{$intersection}{value}, "\n";
####
id|k |value
--+---------+--------------
# |theword |1 (word count)
####
the
20