added a query routine
[spider.git] / perl / dbquery.pl
1 #!/usr/bin/perl
2 # test for independent sql servers
3 # search local then perl directories
4
5 use vars qw($root);
6
7 BEGIN {
8         # root of directory tree for this system
9         $root = "/spider"; 
10         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
11         
12         unshift @INC, "$root/perl";     # this IS the right way round!
13         unshift @INC, "$root/local";
14 }
15
16 use DXUtil;
17 use DXDebug;
18 use ARRL::DX;
19
20 print "usage:\tdbquery.pl <words>\n\teg: dbquery.pl rtty lebanon\n\n" unless @ARGV;
21
22 my $width = $ENV{'COLUMNS'} || $ENV{'COLS'} || 80;
23 my $dx = ARRL::DX->new();
24 my @out = $dx->query(q=>join(' ', @ARGV));
25
26 foreach my $ref (@out) {
27         my $s = cldate($ref->[1]);
28         for (split /\s+/, "$ref->[0] [$ref->[2]]") {
29                 if (length($s) + length($_) + 1 < $width ) {
30                         $s .= ' ' if length $s;
31                         $s .= $_;
32                 } else {
33                         print "$s\n";
34                         $s = $_;
35                 }
36         }
37         print "$s\n" if length $s;
38         print "\n";
39 }
40
41 exit 0;