Skip to content

Instantly share code, notes, and snippets.

@larsen
Created February 14, 2012 16:19
Show Gist options
  • Save larsen/1827859 to your computer and use it in GitHub Desktop.
Save larsen/1827859 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use feature qw/ say /;
my $timeout = 10; # seconds
my $maxlines = 10;
eval {
local $SIG{ ALRM } = sub {
say "Reading...";
my $counter = 0;
while ( $counter < $maxlines ) {
my $line = <>;
print "$counter: $line";
$counter++;
}
alarm $timeout;
};
say "Starting...";
alarm $timeout;
while ( 1 ) {}
};
if ( $@ ) {
die "$@";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment