Dear list,

The MARC::Doc::Tutorial contains a Z39.50 subsection which is
illustrated by the zm.pl program. The example included in the tutorial
uses the traditional Z3950 module.
The version below is an equivalent which uses the ZOOM interface.
This version may be included in the tutorial if it is considered
interesting.

Best wishes,
Sébasien.

zm.pl
=====
#!/usr/bin/perl -w

# GET-MARC-ISBN -- Get MARC records by ISBN from a Z39.50 server
use strict;
use Carp;
use ZOOM;
use MARC::Record;

exit if ($#ARGV < 0);

# We handle multiple ISBNs in the same query by assembling a
# (potentially very large) search string with Prefix Query Notation
# that ORs the ISBN-bearing attributes.
#
# For purposes of automation, we want to request batches of many MARC
# records.  I am not a Z39.50 weenie, though, and I don't know
# offhand if there is a limit on how big a PQN query can be...

my $zq = "\...@attr 1=7 ". pop();
while (@ARGV) { $zq = '@or @attr 1=7 '. pop() ." $zq" }

## HERE IS THE CODE FOR Z3950 REC RETRIEVAL
# Set up connection management structures, connect
# to the server, and submit the Z39.50 query.

my $conn = new ZOOM::Connection(
  'z3950.bnf.fr',
  2211,
  databaseName => "TOUT",
  user => "Z3950",
  password => "Z3950_BNF",
  elementSetName => "f",
  preferredRecordSyntax => "1.2.840.10003.5.1" # UNIMARC
);
croak "Unable to connect to server" if !defined($conn);

my $rs = $conn->search_pqf($zq); # result set

my $numrec = $rs->size();
print STDERR "$numrec record(s) found\n";

for (my $i = 0; $i < $numrec; $i++) {
  # Extract MARC records from Z3950
  # result set, and load MARC::Record.
  my $zrec = $rs->record($i);
  my $mrec = MARC::Record->new_from_usmarc($zrec->raw());
  print $mrec->as_formatted, "\n";
}

Reply via email to