File: tail-logfile.pl

package info (click to toggle)
libio-async-perl 0.51-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,052 kB
  • sloc: perl: 11,110; makefile: 8
file content (32 lines) | stat: -rw-r--r-- 599 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl

use strict;
use warnings;

use IO::Async::Loop;
use IO::Async::FileStream;

my $FILE = shift @ARGV or die "Need FILE";

my $loop = IO::Async::Loop->new;

open my $fh, "<", $FILE or die "Cannot open $FILE for reading - $!";
my $filestream = IO::Async::FileStream->new(
   read_handle => $fh,
   on_initial => sub {
      my ( $self ) = @_;
      $self->seek_to_last( "\n" );
   },
   on_read => sub {
      my ( undef, $buffref ) = @_;

      while( $$buffref =~ s/^(.*)\n// ) {
         print "$FILE: $1\n";
      }

      return 0;
   },
);
$loop->add( $filestream );

$loop->run;