DBZ_File

 view release on metacpan or  search on metacpan

DBZ_File.pm  view on Meta::CPAN


    # Find an entry and output its line from the history file
    if (defined($pos = $hist{'<1234@clari.net>'})) {
	seek(HFP, $pos, 0);
	$_ = <HFP>;
	print;
    }

    # Write a new entry at the EOF
    seek(HFP, 0, 2);
    $msgid = '<54321@clari.net>';
    $hist{$msgid} = tell(HFP);
    print HFP "$msgid\t", time, "~-~0\n";

    close(HFP);
    untie(%hist);

=head1 AUTHOR

DBZ_File was written by Wayne Davison <wayne@clari.net>.  It is
based on the NDBM_File module with a few ideas derived from an old
alpha release written by Ian Phillipps <ian@pipex.net>.  The dbz
module has many names on it, and is copyright 1988 Jon Zeeff.

test.pl  view on Meta::CPAN


BEGIN { $| = 1; print "1..4\n"; }
END {print "not ok 1\n" unless $loaded;}
use DBZ_File;
$loaded = 1;
print "ok 1\n";

######################### End of black magic.

$filename = 'testing';
@msgids = qw(<1@msgid.com> <2@domain.com> <blurle3@clari.net>);
@offsets = qw(0 26 53);

open(FP, ">$filename") || die "Unable to open $filename: $!";
tie(%hist, DBZ_File, $filename, 1, 0664) || die $!;

foreach (@msgids) {
    $pos = tell(FP);
    print FP "$_\t1234~-~4321\n";
    $hist{$_} = $pos;
}
print 'not ' if !(-s "$filename.pag");
print "ok 2\n";

untie(%hist);
undef(%hist);
close(FP);

open(FP, "<$filename") || die "Unable to open $filename: $!";
tie(%hist, DBZ_File, $filename) || die $!;

foreach (@msgids) {
    $val = $hist{$_};
    $should_be = shift @offsets;
    if ($val != $should_be) {
	##print "($val != $should_be) ";
	print 'not ';
	last;
    }
}
print "ok 3\n";



( run in 1.764 second using v1.01-cache-2.11-cpan-97f6503c9c8 )