Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: dbm and news history Message-ID: <100525@convex.convex.com> Date: 12 Mar 90 12:23:09 GMT References: <1990Mar11.130242.11596@pegasus.com> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 38 In article <1990Mar11.130242.11596@pegasus.com> richard@pegasus.com (Richard Foulk) writes: >I'm having a little trouble figuring out just how to use the dbm stuff >in perl. Can someone give me an example of how to find an entry in >/usr/lib/news/history given the usual key (e.g. <123@xyz.UUCP>), >assuming the usual multi-megabyte history{,.pag} files? This should do it -- it's out of my examples suite. --tom #!/usr/bin/perl # # xpost -- given article id's, check news history dbm file # for what newsgroups they're in. shows how to # use associative arrays and bind them to external files. $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!"