New
[ZOOM-Perl-moved-to-github.git] / samples / net-z3950 / zoomtst1.pl
1 # $Id: zoomtst1.pl,v 1.1 2005-10-12 11:53:00 mike Exp $
2 #
3 # See ../README for a description of this program.
4 # perl -I../../blib/lib -I../../blib/arch zoomtst1.pl <target> <query>
5
6 use strict;
7 use warnings;
8 use Net::Z3950;
9
10 if (@ARGV != 2) {
11     print STDERR "Usage: $0 target query\n";
12     print STDERR "      eg. $0 bagel.indexdata.dk/gils computer\n";
13     exit 1;
14 }
15
16 my($host, $query) = @ARGV;
17
18 ### Database name defaults to "Default" in Net::Z3950 and must be overridden
19 $host =~ s/\/(.*)//;
20 my $db = $1;
21 my $conn = new Net::Z3950::Connection($host, 0, databaseName => $db)
22     or die "can't connect to '$host': $!";
23
24 ### Default format is GRS-1 in Net::Z3950
25 $conn->option(preferredRecordSyntax => "usmarc");
26
27 ### Default format is "B" in Net::Z3950
28 $conn->option(elementSetName => "F");
29
30 my $rs = $conn->search(-prefix => $query)
31     or die "can't search for '$query': ", $conn->errmsg();
32 my $n = $rs->size();
33
34 ### Note that the record-index is 1-based here, 0-based in ZOOM-C
35 for my $i (1..$n) {
36     my $rec = $rs->record($i)
37         or die "can't fetch record $i: ", $rs->errmsg();
38     print "=== Record $i of $n ===\n";
39
40     ### Rendering format for MARC records is different
41     print $rec->render(), "\n";
42 }
43
44 $rs->delete();
45 $conn->close();