저는 Perl이나 BerkelyDB에 대한 경험이 없습니다. 나는 이메일 목록과 유닉스 타임스탬프가 포함된 거대한 BerleleyDB를 가지고 있습니다. 100일이 넘은 오래된 타임스탬프가 있는 이메일을 제거하는 데 도움이 필요합니다.
Perl 코드의 이 섹션이 있습니다.
#!/usr/local/perls/perl-5.26.1/bin/perl
use BerkeleyDB;
my $filename = '/usr/local/assp/whitelist.bdb';
my $dbh = new BerkeleyDB::Hash(
-Filename => $filename)
or die "Error opening $filename : $! $BerkeleyDB::Error\n";
my $cursor = $dbh->db_cursor() ;
while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
print "Key: " . $k . ", value: " . $v . "\n";
}
### Close the Berkeley DB
untie $filename;
exit;
키($k)와 값($v)이 있는 모든 행을 표시합니다.
결과는 다음과 같습니다
Key: [email protected], value: 1578560300
Key: [email protected],[email protected], value: 1578643050
Key: [email protected], value: 1578643050
누구나 Perl 코드를 추가하여 제거하는 데 도움을 줄 수 있습니다.~하는 동안위의 실행에서 100일보다 오래된 Unix 타임스탬프 값을 가진 모든 키 행?
답변1
그냥 사용c_del
문서화된 대로, 즉
my $long_ago = time() - 100*24*60*60; # 100 days ago
...
while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
if ($v<$long_ago) {
$cursor->c_del();
}
}