#!/usr/bin/perl -w use strict; use warnings; use DB_File; use DBM_Filter; use Compress::Zlib; die "please provide a database name" unless $ARGV[0]; my $db = tie my %db, 'DB_File', "$ARGV[0].zdb", O_RDWR |O_CREAT or die "could not open $ARGV[0]: $!"; $db->Filter_Value_Push( Fetch => sub { $_ = uncompress $_ unless /^#REDIRECT/ }, Store => sub { $_ = compress $_ unless /^#REDIRECT/ }, ); END { undef $db, untie %db and warn "database properly closed" } $SIG{$_} = sub { die 'caught signal ' . shift } for qw(HUP TERM INT); my ($title, $text); while () { if ( s,^/mediawiki/page/title=,, ) { chomp; $title = $_ } elsif ( s,^/mediawiki/page/revision/text=,, ) { $text .= $_ } elsif ( m{^/mediawiki/page$} ) { $db{$title} = $text; undef $text; } }