Guest User

Untitled

a guest
May 26th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #!perl
  2.  
  3. # this is 'tail' program which can be working on windows.
  4. # on win32, perl's select() can't handle STDIN.
  5. use strict;
  6. use warnings;
  7. use Filesys::Notify::Simple;
  8.  
  9. $|=1;
  10. my $file = shift or die "usage: tail.pl [file]";
  11. open my $fh, '<', $file;
  12. seek $fh, 0, 2;
  13. my $pos = tell($fh);
  14. close $fh;
  15. my $watcher = Filesys::Notify::Simple->new([ $file ]);
  16. while (1) {
  17. $watcher->wait(sub {
  18. open $fh, '<', $file or die "maybe file was deleted?";
  19. seek $fh, $pos, 0;
  20. print $_ while <$fh>;
  21. seek $fh, 0, 2;
  22. $pos = tell($fh);
  23. close $fh;
  24. });
  25. }
Add Comment
Please, Sign In to add comment