Skip to content

Instantly share code, notes, and snippets.

@rlb3
Created June 6, 2013 15:39
Show Gist options
  • Select an option

  • Save rlb3/5722501 to your computer and use it in GitHub Desktop.

Select an option

Save rlb3/5722501 to your computer and use it in GitHub Desktop.
tail-like
#!/usr/bin/env perl
use strict;
use warnings;
my $pid = $ARGV[0];
my $file = '/tmp/logfile.log';
open my $fh, '<', $file;
while (pid_exists()){
while (my $line = readline($fh)) {
print $line;
}
sleep 1;
seek $fh, 0, 1; # this clears the eof flag on $fh
}
sub pid_exists {
return kill 0, $pid;
}
#!/usr/bin/env perl
use strict;
use warnings;
$|++;
open my $log_fh, '>', '/tmp/logfile.log';
my $count = 1;
print $$, "\n";
while (1) {
syswrite $log_fh, $count . "\n";
$count++;
sleep 2;
}
close $log_fh;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment