#!/usr/bin/perl -w
# Created: Mon Oct 30 10:56:57 2000
# Last modified: Sat Jun  9 21:50:31 2001
# Time-stamp: <01/06/09 21:50:31 kapur>

## $Id: msn.pl,v 1.2 2001/07/24 14:00:01 kapur Exp $

## $Log: msn.pl,v $
## Revision 1.2  2001/07/24 14:00:01  kapur
##
## Modified Files:
##  	dilbert.pl msn.pl rc.iptables
##

use strict;
use LWP::UserAgent;
use HTTP::Request::Common;

my ($author, $title);

for (my $i = 0; $i le $#ARGV-1; $i++) {
  $author = $ARGV[$i+1] if $ARGV[$i] =~ m/^-au*/;
  $title = $ARGV[$i+1] if $ARGV[$i] =~ m/^-ti*/;
}

die "Exiting: neither author nor title specified.\nUsage: $0 -a <author> -t <title>\n" unless (defined $author or defined $title);

$author = '' unless defined $author;
$title = '' unless defined $title;

my $ua = LWP::UserAgent->new;
my $response = $ua->request(POST 'http://www.ams.org/msnmain/MathSci',
			    [bdlback => 'r=1',
			     dr      => 'all',
			     l       => 20,
			     pg3     => 'TI',
			     s3      => $title,
			     pg4     => 'ICN',
			     s4      => $author,
			     fn      => '130',
			     fmt     => 'bibtex',
			     bdlall  => 'Retrieve+All']);
if ($response->is_success){
  if ($response->as_string =~ /No Records Selected/){
    warn "I couldn't find any entries with '$title' in the title by '$author'.\n";
  }
  else{
    map {print $_, "\n" if (/^<PRE>/ .. /^<\/PRE>/ and not
				m{^</?PRE>})}
      split "\n", $response->as_string;
  }
}

__END__

=head1 NAME

  msn - get BibTeX entries from MathSciNet

=head1 SYNOPSIS

  msn -a <author> -t <title>

  Either the author or the title must be specified.

=head1 AUTHOR

  Nevin Kapur <nevin@jhu.edu>

=cut

