Created
September 6, 2011 20:38
-
-
Save sugar84/1198879 to your computer and use it in GitHub Desktop.
AnyEvent tail
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 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