+#!/usr/bin/perl
#
# grep for expressions in various fields of the dx file
#
use spot;
# initialise spots file
+STDOUT->autoflush(1);
+
+print "reading in spot data ..";
+$t = time;
$count = spot->init();
+$t = time - $t;
+print "done ($t secs)\n";
dbgadd('spot');
print "$count database records read in\n";
-STDOUT->autoflush(1);
-
#loada();
for (;;) {
print "field: ";
my $ref = spot->open(@first);
if ($ref) {
my $fh = $ref->{fh};
+ my @out = ();
while (<$fh>) {
chomp;
my @ent = split /\^/;
- unshift @spot::table, [ @ent ]; # stick this ref to anon list on the FRONT of the table
- ++$count;
+
+ push @spot::table, \@ent; # stick this ref to anon list on the FRONT of the table
+
+ ++$count;
}
}
@first = julian->add(@first, 1);
$spot[2] = 0 + $spot[2];
# save it on the front of the list
- unshift @spot::table, [ @spot ];
+ unshift @spot::table, \@spot;
# compare dates to see whether need to open a other save file
my @date = julian->unixtoj($spot[2]);
#
sub search
{
- my ($pkg, $field, $expr) = @_;
+ my ($pkg, $field, $expr, $from, $to) = @_;
my $eval;
my @out;
my $ref;
+ my $i;
dbg('spot', "input expr = $expr\n");
if ($field == 0 || $field == 2) { # numeric fields
# build up eval to execute
$eval = qq(foreach \$ref (\@spot::table) {
- push \@out, \$ref if $expr;
+ next if \$i < \$from;
+ if ($expr) {
+ unshift(\@out, \$ref);
+ \$i++;
+ last if \$to && \$i >= \$to;
+ }
});
dbg('spot', "eval = $eval\n");
eval $eval; # execute it