d40903f05505d8fd696673bed2c343e8d05879f9
[ZOOM-Perl-moved-to-github.git] / samples / zoom / zoomtst1.pl
1 #!/usr/bin/perl -w
2
3 # $Id: zoomtst1.pl,v 1.6 2007-08-17 18:35:17 mike Exp $
4 #
5 # See ../README for a description of this program.
6 # perl -I../../blib/lib -I../../blib/arch zoomtst1.pl <target> <query>
7
8 use strict;
9 use warnings;
10 use ZOOM;
11
12 if (@ARGV < 2 || @ARGV %2 == 1) {
13     print STDERR "Usage: $0 target query [<option> <value> ...]\n";
14     print STDERR "      eg. $0 z3950.indexdata.dk/gils computer\n";
15     exit 1;
16 }
17 my $host = shift(@ARGV);
18 my $query = shift(@ARGV);
19
20 eval {
21     my $conn = new ZOOM::Connection($host, 0);
22     $conn->option(preferredRecordSyntax => "usmarc");
23     while (@ARGV) {
24         my $key = shift(@ARGV);
25         my $value = shift(@ARGV);
26         $conn->option($key => $value);
27     }
28
29     my $rs = $conn->search_pqf($query);
30     my $n = $rs->size();
31     print "Query '$query' found $n records\n";
32     for my $i (0..$n-1) {
33         my $rec = $rs->record($i);
34         print "=== Record ", $i+1, " of $n ===\n";
35         print $rec->render();
36     }
37     
38     $rs->destroy();
39     $conn->destroy();
40 }; if ($@) {
41     die "Non-ZOOM error: $@" if !$@->isa("ZOOM::Exception");
42     print STDERR "Error ", $@->code(), ": ", $@->message();
43     print STDERR " (", $@->addinfo(), ")" if $@->addinfo();
44     print STDERR "\n";
45     exit 1;
46 }