-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtc_retrieve_hash.pl
46 lines (40 loc) · 1.05 KB
/
tc_retrieve_hash.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use TokyoCabinet;
use strict;
use warnings;
# create the object
my $hdb = TokyoCabinet::HDB->new();
# open the database
if(!$hdb->open("urldb_hash.tch", $hdb->OREADER)) {
my $ecode = $hdb->ecode();
printf STDERR ("open error: %s\n", $hdb->errmsg($ecode));
}
$hdb->tune(10_000_000);
my $urls;
eval { open($urls, "url_cat.txt") };
if($@) {
die "Cannot open url_cat.txt";
}
#for(my $i=0; $i < 10; $i++) {
while(<$urls>) {
chomp;
my ($url, $cat) = split(/\t/, $_);
# retrieve records
my $v;
if (!($v = $hdb->get($url))) {
# if (!(($v) = $hdb->fwmkeys($url, 256+64))) {
my $ecode = $hdb->ecode();
printf STDERR ("put error: %s\n", $hdb->errmsg($ecode));
} else {
unless ($v eq $cat) {
print "Doesn't match between $v and $cat\n";
print "URL:$url\n";
}
}
}
#}
print "\n";
# close the database
if(!$hdb->close()){
my $ecode = $hdb->ecode();
printf STDERR ("close error: %s\n", $hdb->errmsg($ecode));
}