Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.40 KB | None | 0 0
  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.     if (m{ \A ( \d+ ) .* $search_word }xs) {
  24.         push @searched_res_body,   $_;
  25.         push @searched_res_number, $1;
  26.     }
  27. }
  28.  
  29. PRINT_SEARCHED_RES_AND_THOSE_WHO_ANCHER:
  30. for (@searched_res_body) {
  31.     print;
  32.     my $searched_res_number = shift @searched_res_number;
  33.  
  34.     PRINT_THOSE_WHO_ANCHER:
  35.     for my $each_res (@whole_res) {
  36.         state $i = 1;
  37.         next PRINT_THOSE_WHO_ANCHER if ( $i++ <= $searched_res_number );
  38.         if ( $each_res =~ m{ [>]+ ( [\d-,]+ ) }x ) {
  39.             my $mix_anchors = $1;
  40.             my @anchors = sort{$a<=>$b} eval $mix_anchors =~ s/[-]/.../gr;
  41.             if (grep {/\A $searched_res_number \z/x} @anchors) {
  42.                 print $each_res;
  43.             }
  44.         }
  45.     }
  46.     print "-" x 80, "\n";
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement