Raku By Example
View me onGitHub
for $=finish.lines -> $line {
    say $line if !($line ~~ m/^\;/ ff $line ~~ m/^\"/);
}

## `$line ~~ m/^\;/ ff $line ~~ m/^\"/` 过滤掉 `;` 和 `"` 之间的内容, 再对它进行取反操作就是过滤后剩下的文本。


=finish
; next is some lines to skip,include this line
fuck fuck fuck
dam dam dam
mie mie mie
" next is subject
There is more than one way to do it
                                -- Larry Wall

We hope Perl6 is wrote by the hole Socfilia
                                -- Larry Wall
; next is some lines to skip,include this line
fuck fuck fuck
dam dam dam
mie mie mie
" next is subject
Programming is hard,Let's go shopping
                               -- Larry Wall
Ruby is Another Perl6
                               -- Larry Wall




# --------------------------------------------------

my $excerpt = q:to/END/;
Here's some unimportant text.
=begin code
This code block is what we're after.
We'll use 'ff' to get it.
=end code
More unimportant text.
=begin code
I want this line.
and this line as well.
HaHa
=end code
More unimport text.
=begin code
Let's to go home.
=end code
END

say ( $excerpt ~~ m:s:g{\=begin code\s+(.+?)\s+\=end code} ).map( *.[0] ).join("\n\n")

# ------------------------------------------------------

my $excerpt = q:to/END/;
Here's some unimportant text.
=begin code
    This code block is what we're after.
    We'll use 'ff' to get it.
=end code
More unimportant text.
=begin code
    Today rains heavy.
    Long live AI .
    HaHa
=end code
More unimport text.
=begin code
    Like to go home.
=end code
END

my @codelines = gather for $excerpt.lines {
    take $_ if "=begin code" ff "=end code"
}

# this will print four lines, starting with "=begin code" and ending with
# "=end code"
#say @codelines.join("\n");

my @lines = gather {
  my @current;

  for $excerpt.lines {

    if "=begin code" ^ff^ "=end code" {

      # collect the values between matches
      push @current, .trim;

    } else {
      # take the next value between matches

      # don't bother if there wasn't any values matched
      if @current {

        # you must do something so that you aren't
        # returning the same instance of the array
        take @current.List;
        @current = ();
      }
    }
  }
}

.Str.say for @lines;


## 比较前后两条时间差是否大于 5 分钟

.say if (.max - .min) >= 5 * 60 * 1000 for $=finish.lines.rotor(2 => -1);
=finish
1564627891000
1564627892000
1564627893000
.............


## rotor

my %re;
for 'input.txt'.IO.lines».rotor(2, :partial) -> $header, $data {
    my $key = $header;
    $key ~~ s/<upper>$//;
    %re{$key} ~= $data;
}

for %re.kv -> $key, $value {
    say "$key\n$value";
}