# open the file, seek to the end, then seek backward from the end a bit and start reading
# but ignore the first line 'cos it will be incomplete.
open I, $fn or die "cannot open $fn ($!)\n";
- seek(I, 0, 2);
- my $pos = tell(I);
+ my $pos = sysseek(I, 0, 2);
if ($pos <= int(abs($lines * 80))) {
- seek(I, 0, 0);
+ sysseek(I, 0, 0);
} else {
- seek(I, $pos + ($lines * 80), 0); # remember lines is (-)ve
+ sysseek(I, $pos + ($lines * 80), 0); # remember lines is (-)ve
}
- my $buf; # input overflow buffer
my $count;
while (!$end) {
if ($state) {
- my $l = <I>;
- if (defined $l) {
- if ($l =~ /\cJ$/) {
- my $s = "$buf$l";
+ my $l;
+ my $r = sysread(I, $l, 4096);
+ if (defined $r && length $l) {
+ my @lines = split /\cM?\cJ/, $l;
+ foreach my $s (@lines) {
if (@pattern) {
unless (match($s)) {
- $buf = '';
next;
}
}
- print $s;
- $buf = '';
- next;
- } else {
- $buf .= $l;
+ print "\n".$s;
}
}
$count = 0;
$state ^= 1;
print $state ? "\nRunning..." : "\nStopped...";
}
- seek(I, 0, 1);
+ sysseek(I, 0, 1);
STDOUT->flush;
- # runout any stored stuff if we haven't seen anything recently
- if ($state && length $buf && ++$count > 2) {
- if (@pattern) {
- print $buf if match($buf);scalar @pattern == grep $buf =~ m{$_}i, @pattern;
- } else {
- print $buf;
- }
-# print " *** XTRA! ***";
- $buf = '';
- }
-
# move onto the next file if we roll over midnight
my ($d) = (gmtime)[3];
last if ($d != $dd);
close I;
}
+print "\n";
+exit(0);
+
sub match
{
my $count = 0;
return 0;
}
-exit(0);
-