Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!perl
- # this is 'tail' program which can be working on windows.
- # on win32, perl's select() can't handle STDIN.
- use strict;
- use warnings;
- use Filesys::Notify::Simple;
- $|=1;
- my $file = shift or die "usage: tail.pl [file]";
- open my $fh, '<', $file;
- seek $fh, 0, 2;
- my $pos = tell($fh);
- close $fh;
- my $watcher = Filesys::Notify::Simple->new([ $file ]);
- while (1) {
- $watcher->wait(sub {
- open $fh, '<', $file or die "maybe file was deleted?";
- seek $fh, $pos, 0;
- print $_ while <$fh>;
- seek $fh, 0, 2;
- $pos = tell($fh);
- close $fh;
- });
- }
Add Comment
Please, Sign In to add comment