home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / tutorial / eg / xpost < prev    next >
Encoding:
Text File  |  1990-01-14  |  644 b   |  24 lines

  1. #!/usr/bin/perl
  2. #
  3. # xpost -- given article id's, check news history dbm file
  4. #        for what newsgroups they're in.   shows how to 
  5. #       use associative arrays and bind them to external files.
  6.  
  7. $HIST = '/usr/local/lib/news/history';
  8. dbmopen(HIST,$HIST,0666) || die "$0: couldn't dbmopen $HIST: $!\n";
  9. open HIST || die "$0: couldn't open $HIST: $!\n";
  10.  
  11. foreach $key ( @ARGV ) {
  12.     $key =~ tr/A-Z/a-z/;
  13.     $key = "<$key>" if $key !~ /^<.*>$/;
  14.     $key .= "\000";
  15.     if (!defined $HIST{$key}) {
  16.     print stderr "no article $key\n";
  17.     next;
  18.     } 
  19.     ($pos) = unpack('L',$HIST{$key});
  20.     seek(HIST,$pos,0);
  21.     $line = <HIST>;
  22.     print $line;
  23.