dbm example in perl

Tom Christiansen tchrist at convexe.uucp
Wed Nov 8 17:20:34 AEST 1989


Have you ever seen a reference to a news article by message id that 
didn't have a (newsgroup,article) pair associated with it?  Here's 
a C program that binds an associative array to the DBM version of 
the news history database to retrieve the right text line.  It should
be easy to use this or a derivative in an rn macro.  Requires perl v3.0
to run.

--tom

#!/usr/local/bin/perl
#
# xpost
# written by Tom Christiansen <tchrist at convex.com>
#
# script that takes message ids as args (like 1842 at somehost.uucp)
# and retrieves the line from the text file.  this is 
# much faster than a grep.

$HIST = '/usr/local/lib/news/history';
dbmopen(HIST,$HIST,0666) || die "$0: couldn't dbmopen $HIST: $!\n";
open HIST || die "$0: couldn't open $HIST: $!\n";

foreach $key ( @ARGV ) {
    $key =~ tr/A-Z/a-z/;
    $key = "<$key>" if $key !~ /^<.*>$/;
    $key .= "\000";
    if (!defined $HIST{$key}) {
	print stderr "no article $key\n";
	next;
    } 
    ($pos) = unpack('L',$HIST{$key});
    seek(HIST,$pos,0);
    $line = <HIST>;
    print $line;
} 

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist at convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"



More information about the Alt.sources mailing list