Skip to content

Instantly share code, notes, and snippets.

@sugar84
Created September 6, 2011 20:38
Show Gist options
  • Select an option

  • Save sugar84/1198879 to your computer and use it in GitHub Desktop.

Select an option

Save sugar84/1198879 to your computer and use it in GitHub Desktop.
AnyEvent tail
#!/usr/bin/env perl
use AnyEvent;
if (open my $fh, "|-", "tailf -n 10 ./file") {
1;
} else {
my $cv = AnyEvent->condvar;
my $body;
my $handle; $handle = AnyEvent::Handle->new(
fh => $fh,
on_error => sub {
warn "error!";
$handle->destroy;
},
on_eof => sub {
warn "the end";
$handle->destroy;
},
on_read => sub {
$body .= $_[0]->rbuf;
$_[0]->rbuf = "";
print $body;
},
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment