daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Dec 15th, 2017 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env perl6
  2.  
  3. sub follow(IO::Handle $fh --> Supply) {
  4.     $fh.seek(0, SeekFromEnd);
  5.     supply {
  6.         whenever $fh.lines {
  7.             .emit;
  8.             QUIT { note "QUIT ", &?ROUTINE; }
  9.             LAST { note "QUIT ", &?ROUTINE; }
  10.         }
  11.     }
  12. }
  13.  
  14. sub grep($pattern, Supply $lines --> Supply) {
  15.     supply {
  16.         whenever $lines -> $line {
  17.             if $line.contains($pattern) {
  18.                 $line.emit;
  19.             }
  20.             QUIT { note "QUIT ", &?ROUTINE; }
  21.             LAST { note "QUIT ", &?ROUTINE; }
  22.         }
  23.     }
  24. }
  25.  
  26. sub MAIN(Str $file = "sandbox/bbb.log") {
  27.     my $fh = open($file, :r);
  28.     react {
  29.         whenever &grep("perl6", &follow($fh)) {
  30.             .say;
  31.             QUIT { note "QUIT ", &?ROUTINE; }
  32.             LAST { note "QUIT ", &?ROUTINE; }
  33.         }
  34.     }
  35.     $fh.close();
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top