Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!samsung!uunet!convex!convexe!tchrist
From: tchrist@convexe.uucp (Tom Christiansen)
Newsgroups: alt.sources
Subject: dbm example in perl
Keywords: dbm news perl
Message-ID: <2885@convex.UUCP>
Date: 8 Nov 89 06:20:34 GMT
Sender: news@convex.UUCP
Reply-To: tchrist@convex.Com (Tom Christiansen)
Distribution: alt
Organization: Convex Computer Corporation, Richardson, Tx.
Lines: 39

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 
#
# script that takes message ids as args (like 1842@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 = ;
    print $line;
} 

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in : Editor too big!"