Use z3950.indexdata.com instead of bagel.indexdata.com everywhere
[ZOOM-Perl-moved-to-github.git] / samples / zoom / zoomtst1.pl
1 # $Id: zoomtst1.pl,v 1.4 2006-11-02 17:48:26 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 ZOOM;
9
10 if (@ARGV != 2) {
11     print STDERR "Usage: $0 target query\n";
12     print STDERR "      eg. $0 z3950.indexdata.dk/gils computer\n";
13     exit 1;
14 }
15 my($host, $query) = @ARGV;
16
17 eval {
18     my $conn = new ZOOM::Connection($host, 0);
19     $conn->option(preferredRecordSyntax => "usmarc");
20     my $rs = $conn->search_pqf($query);
21     my $n = $rs->size();
22     print "Query '$query' found $n records\n";
23     for my $i (0..$n-1) {
24         my $rec = $rs->record($i);
25         print "=== Record ", $i+1, " of $n ===\n";
26         print $rec->render();
27     }
28     
29     $rs->destroy();
30     $conn->destroy();
31 }; if ($@) {
32     die "Non-ZOOM error: $@" if !$@->isa("ZOOM::Exception");
33     print STDERR "Error ", $@->code(), ": ", $@->message();
34     print STDERR " (", $@->addinfo(), ")" if $@->addinfo();
35     print STDERR "\n";
36     exit 1;
37 }