- $search = '1' unless $pattern || $who;
- $search = "\$ref->[1] =~ /$pattern/i" if $pattern;
- $search .= ' && ' if $pattern && $who;
- $search .= "(\$ref->[2] =~ /$who/i || \$ref->[3] =~ /$who/i)" if $who;
- $eval = qq(
- my \$c;
- my \$ref;
- for (\$c = \$#in; \$c >= 0; \$c--) {
- \$ref = \$in[\$c];
- if ($search) {
- \$count++;
- next if \$count < $from;
- push \@out, print_item(\$ref);
- last if \$count >= \$to; # stop after n
- }
- }
- );
+ $who = uc $who if defined $who;
+
+ if ($pattern) {
+ $hint = q{m{\Q$pattern\E}i};
+ } else {
+ $hint = q{!m{\^(?:ann|rcmd|talk|chat)\^}};
+ }
+ if ($who) {
+ $hint .= ' && ' if $hint;
+ $hint .= q{m{\Q$who\E}oi};
+ }
+ $hint = "next unless $hint" if $hint;
+ $hint .= "; next unless m{^\\d+\\^$pattern\\^}" if $pattern;
+ $hint ||= "";
+
+ $eval = qq(while (<\$fh>) {
+ $hint;
+ chomp;
+ # say "line: \$_";
+ push \@in, \$_;
+ last L1 if \@in >= $tot;
+ } );
+
+ if (isdbg('search')) {
+ dbg("sh/log hint: $hint");
+ dbg("sh/log eval: $eval");
+ }