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