ProfessorHaroldHill has asked for the wisdom of the Perl Monks concerning the following question:

So its a realtime tail with a line count I'm after.
Can anyone give me some pointers as to where to start to tackle the problem with Perl ?
I'm stumped. mknod ? mkfifo ?
regards Kev
The sadder but wiser Perl for me ...

Replies are listed 'Best First'.
Re: tail -f foo.bar | cat -n
by svenXY (Deacon) on Feb 26, 2008 at 09:43 UTC
    Hi,
    File::Tail can do it for you...
    my $count = 0; my $line; # from their POD use File::Tail; # "tail => -1" will start from the beginning of the file my $file=File::Tail->new(name => "/some/log/file", tail => -1); while (defined($line=$file->read)) { print ++$count, " ", $line; }

    Regards,
    svenXY

    update: added the actual line output to mimic cat -n correctly
    update 2: works for me
    update 3: added tail => -1 (see comment)
      Looks good on my test suite too, thank you Kev
      The sadder but wiser Perl for me ...