Created
June 16, 2014 13:32
-
-
Save kuniyoshi/121915a18866c3419feb to your computer and use it in GitHub Desktop.
This script prints STDIN, or lines of files which are ARGS. I have a situation that slow print down to STDOUT to see what were print. I saw these lines to check does it almost good. But some times, STDOUT is too fast to see it, thus, this script slows STDOUT down.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -s | |
use utf8; | |
use strict; | |
use warnings; | |
use Time::HiRes qw( sleep ); | |
use constant LINES_PER_SECOND => 100; | |
our $lps ||= LINES_PER_SECOND; | |
our $h; | |
if ( $h ) { | |
die <<END_USAGE | |
usage: $0 [-lps=100] | |
lps: is lines per second | |
END_USAGE | |
} | |
my $sleep_seconds = 1 / $lps; | |
$|++; | |
while ( <> ) { | |
print; | |
sleep $sleep_seconds; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment