Skip to content

Instantly share code, notes, and snippets.

@bduggan
Created September 26, 2012 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bduggan/3789250 to your computer and use it in GitHub Desktop.
Save bduggan/3789250 to your computer and use it in GitHub Desktop.
poll
#!/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;
#!/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;
}
#!/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