Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use feature 'state';
- my $search_word = @ARGV ? shift @ARGV : ".";
- my ( @whole_res, $each_res, @searched_res_number, @searched_res_body );
- SEPARETE_EACH_RES_FROM_STDIN:
- while (<STDIN>) {
- state $res_number = 2;
- my $header_of_each_res
- = qr/ .* \d{4} . \d{2} . \d{2} .* \d{2} : \d{2} : \d{2} /x;
- if (m{^ (?= $res_number $header_of_each_res) }xm) {
- push @whole_res, $each_res;
- $each_res = q{};
- ++$res_number; # rough solution with quite seldome occur bug
- }
- $each_res .= $_;
- }
- push @whole_res, $each_res; # this line push final res.
- FIND_SEARCHED_RES:
- for (@whole_res) {
- if (m{ \A ( \d+ ) .* $search_word }xs) {
- push @searched_res_body, $_;
- push @searched_res_number, $1;
- }
- }
- PRINT_SEARCHED_RES_AND_THOSE_WHO_ANCHER:
- for (@searched_res_body) {
- print;
- my $searched_res_number = shift @searched_res_number;
- PRINT_THOSE_WHO_ANCHER:
- for my $each_res (@whole_res) {
- state $i = 1;
- next PRINT_THOSE_WHO_ANCHER if ( $i++ <= $searched_res_number );
- if ( $each_res =~ m{ [>]+ ( [\d-,]+ ) }x ) {
- my $mix_anchors = $1;
- my @anchors = sort{$a<=>$b} eval $mix_anchors =~ s/[-]/.../gr;
- if (grep {/\A $searched_res_number \z/x} @anchors) {
- print $each_res;
- }
- }
- }
- print "-" x 80, "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement