Created
September 26, 2012 17:11
-
-
Save bduggan/3789250 to your computer and use it in GitHub Desktop.
poll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Linux::Inotify2; | |
my $filename = $ARGV[0] or die "need a filename"; | |
# create a new object | |
my $inotify = new Linux::Inotify2 or die "unable to create new inotify object: $!"; | |
# add watchers | |
$inotify->watch ($filename, IN_CLOSE_WRITE, sub { | |
my $e = shift; | |
my $name = $e->fullname; | |
print "write to $name\n"; | |
}); | |
# manual event loop | |
1 while $inotify->poll; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use File::stat qw/stat/; | |
my $filename = $ARGV[0] or die "missing filename"; | |
my $last; | |
$last = stat($filename)->mtime; | |
while (1) { | |
my $this = stat($filename)->mtime; | |
print "write to $filename\n" if $this != $last; | |
$last = $this; | |
sleep 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Linux::Inotify2; | |
my $dirname = $ARGV[0] or die "need a dirname"; | |
# create a new object | |
my $inotify = new Linux::Inotify2 or die "unable to create new inotify object: $!"; | |
# add watchers | |
$inotify->watch ($dirname, IN_MOVED_TO, | |
sub { | |
my $e = shift; | |
my $name = $e->fullname; | |
print "new file $name was moved into $dirname\n"; | |
}); | |
# manual event loop | |
1 while $inotify->poll; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment