+ $t = time - $t;
+ print "$count records found, $t secs\n";
+}
+
+sub search
+{
+ my ($expr, $from, $to) = @_;
+ my $eval;
+ my @out;
+ my @spots;
+ my $ref;
+ my $i;
+
+
+ $expr =~ s/\$f(\d)/zzzref->[$1]/g; # swap the letter n for the correct field name
+ $expr =~ s/[\@\$\%\{\}]//g; # remove any other funny characters
+ $expr =~ s/\&\w+\(//g; # remove subroutine calls
+ $expr =~ s/eval//g; # remove eval words
+ $expr =~ s/zzzref/\$ref/g; # put back the $ref
+
+ print "expr = $expr\n";
+
+ # build up eval to execute
+ $eval = qq(my \$c;
+ for (\$c = \$#spots; \$c >= 0; \$c--) {
+ \$ref = \$spots[\$c];
+ if ($expr) {
+ push(\@out, \$ref);
+ }
+ });
+
+ my @today = Julian::unixtoj(time);
+ for ($i = 0; $i < 60; ++$i) {
+ my @now = Julian::sub(@today, $i);
+ my @spots;
+ my $fp = Spot->open(@now);
+ if ($fp) {
+ my $fh = $fp->{fh};
+ my $in;
+ foreach $in (<$fh>) {
+ chomp $in;
+ push @spots, [ split('\^', $in) ];
+ }
+ my $ref;
+ eval $eval;
+ return ("error", $@) if $@;
+ }
+ }
+ # execute it
+ return @out;