X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=samples%2Fnet-z3950-zoom%2Fzoomtst3.pl;h=140e5f041309020dddbe59e9a6f1fdd798fb24ae;hb=87c72eaf97a3dbf51a93dab782c2909539addc48;hp=c8675459e79c621e24b55fffdef0f7e28cb30130;hpb=611fbde794d79346b1fded79a1b385395dd9ee55;p=ZOOM-Perl-moved-to-github.git diff --git a/samples/net-z3950-zoom/zoomtst3.pl b/samples/net-z3950-zoom/zoomtst3.pl index c867545..140e5f0 100644 --- a/samples/net-z3950-zoom/zoomtst3.pl +++ b/samples/net-z3950-zoom/zoomtst3.pl @@ -1,7 +1,7 @@ -# $Id: zoomtst3.pl,v 1.1 2006-04-06 13:47:55 mike Exp $ -# # See ../README for a description of this program. # perl -I../../blib/lib -I../../blib/arch zoomtst3.pl [...] +# for example: +# perl -I../../blib/lib -I../../blib/arch zoomtst3.pl z3950.loc.gov:7090/Voyager z3950.indexdata.com:210/gils endeavor.flo.org:7090/Voyager mineral use strict; use warnings; @@ -9,7 +9,7 @@ use Net::Z3950::ZOOM; if (@ARGV < 2) { print STDERR "Usage: $0 target1 target2 ... targetN query\n"; - print STDERR " eg. $0 bagel.indexdata.dk/gils localhost:9999 fish\n"; + print STDERR " eg. $0 z3950.indexdata.dk/gils localhost:9999 fish\n"; exit 1; } @@ -23,7 +23,7 @@ Net::Z3950::ZOOM::options_set($o, count => 10); # Preferred record syntax Net::Z3950::ZOOM::options_set($o, preferredRecordSyntax => "usmarc"); -Net::Z3950::ZOOM::options_set($o, elementSetName => "F"); +Net::Z3950::ZOOM::options_set($o, elementSetName => "B"); # Connect to all targets: options are the same for all of them for (my $i = 0; $i < $n; $i++) { @@ -37,9 +37,15 @@ for (my $i = 0; $i < $n; $i++) { } # Network I/O. Pass number of connections and array of connections -while ((my $i = Net::Z3950::ZOOM::event([ @z ])) != 0) { - print("n = ", $i-1, " event = ", - Net::Z3950::ZOOM::connection_last_event($z[$i-1]), "\n"); +while ((my $i = Net::Z3950::ZOOM::event(\@z)) != 0) { + my $ev = Net::Z3950::ZOOM::connection_last_event($z[$i-1]); + print("connection ", $i-1, ": event $ev (", + Net::Z3950::ZOOM::event_str($ev), ")\n"); + # It would be nice to display results as they come in, but the + # ability to do so is dependent on the END event, which was + # introduced only in YAZ 2.1.17. If you have a sufficiently new + # YAZ, please use the alternative "async.pl", which is similar to + # this program except in its asynchronous display. } # No more to be done. Inspect results @@ -61,14 +67,18 @@ for (my $i = 0; $i < $n; $i++) { # Go through all records at target $size = 10 if $size > 10; for (my $pos = 0; $pos < $size; $pos++) { - my $len; # length of buffer rec - print "$tname: fetching $pos of $size\n"; + print "$tname: fetching ", $pos+1, " of $size\n"; my $tmp = Net::Z3950::ZOOM::resultset_record($r[$i], $pos); - my $rec = Net::Z3950::ZOOM::record_get($tmp, "render", $len); - # if rec is non-null, we got a record for display - if (defined $rec) { - print $pos+1, "\n", $rec, "\n"; + if (!defined $tmp) { + print "$tname: can't get record ", $pos+1, "\n"; + next; } + my $rec = Net::Z3950::ZOOM::record_get($tmp, "render"); + if (!defined $rec) { + print "$tname: can't render record ", $pos+1, "\n"; + next; + } + print $pos+1, "\n", $rec, "\n"; } }