fork download
  1. #!/usr/bin/env perl
  2. use feature 'state';
  3.  
  4. my $search_word = @ARGV ? shift @ARGV : ".";
  5. my ( @whole_res, $each_res, @searched_res_number, @searched_res_body );
  6.  
  7. SEPARETE_EACH_RES_FROM_STDIN:
  8. while (<STDIN>) {
  9. state $res_number = 2;
  10. my $header_of_each_res
  11. = qr/ .* \d{4} . \d{2} . \d{2} .* \d{2} : \d{2} : \d{2} /x;
  12. if (m{^ (?= $res_number $header_of_each_res) }xm) {
  13. push @whole_res, $each_res;
  14. $each_res = q{};
  15. ++$res_number; # rough solution with quite seldome occur bug
  16. }
  17. $each_res .= $_;
  18. }
  19. push @whole_res, $each_res; # this line push final res.
  20.  
  21. FIND_SEARCHED_RES:
  22. for (@whole_res) {
  23. # 3901412020/03/29(F|) 23:48:54.72ID:yB4nr7Bt0 <- 390 not work
  24. if (m{ \A ( \d+ ) .* $search_word }xs) {
  25. push @searched_res_body, $_;
  26. push @searched_res_number, $1;
  27. }
  28. }
  29.  
  30. PRINT_SEARCHED_RES_AND_THOSE_WHO_ANCHER:
  31. for (@searched_res_body) {
  32. my $searched_res_number = shift @searched_res_number;
  33.  
  34. PRINT_THOSE_WHO_ANCHER:
  35. for my $each_res (@whole_res) {
  36. $each_res =~ /\A (\d+)/x;
  37. my $current_res_number = $1;
  38. next PRINT_THOSE_WHO_ANCHER if ( $current_res_number <= $searched_res_number );
  39. if ( $each_res =~ m{ [>]+ ( [\d-,]+ ) }x ) {
  40. my $mix_anchors = $1;
  41. my @anchors = sort{$a<=>$b} eval $mix_anchors =~ s/[-]/.../gr;
  42. if (grep {/\A $searched_res_number \z/x} @anchors) {
  43. print $each_res;
  44. }
  45. }
  46. }
  47. print "-" x 80, "\n";
  48. }
Success #stdin #stdout 0s 5240KB
stdin
Standard input is empty
stdout
Standard output is empty