Skip to content

Instantly share code, notes, and snippets.

@skaji
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skaji/9466001 to your computer and use it in GitHub Desktop.
Save skaji/9466001 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings FATAL => "all";
# http://perldoc.perl.org/functions/seek.html
# tail -f
my $file = shift or die;
open my $fh, "<", $file or die "open $file: $!";
for (;;) {
my ($pos, $line);
for ($pos = tell $fh; $line = <$fh>; $pos = tell $fh) {
print $line;
}
select undef, undef, undef, 0.3;
seek $fh, $pos, 0;
}
#!/usr/bin/env perl
use strict;
use warnings FATAL => "all";
use Sys::Hostname 'hostname';
use POSIX 'strftime';
# http://perldoc.perl.org/functions/seek.html
# tail -f
my $file = shift or die;
open my $fh, "<", $file or die "open $file: $!";
my $host = hostname;
for (;;) {
my ($pos, $line);
my $time = strftime("%F %T", localtime);
for ($pos = tell $fh; $line = <$fh>; $pos = tell $fh) {
print "$time [$host] $line";
}
select undef, undef, undef, 0.3;
seek $fh, $pos, 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment