Last active
February 21, 2024 12:05
-
-
Save liweitianux/0f6e9aa2b3fec01371861001d6c59fca to your computer and use it in GitHub Desktop.
Print lines at particular speed (line/sec)
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/env perl | |
# | |
# Cat file to terminal at particular speed of lines per second | |
# https://superuser.com/a/526249 | |
# | |
# Usage: cat-lps.pl [lps] [file]... | |
# | |
use warnings; | |
use strict; | |
use Time::HiRes qw(time); | |
# auto flush on every output write; so the content will be complete lines | |
# when the output is redirected to a file. | |
$| = 1; | |
my $lps = 300; # default line/second | |
$lps = shift @ARGV if @ARGV && $ARGV[0] =~ /^(\d+)$/; | |
my $sleepPerLine = 1.0 / $lps; | |
my $start = time; | |
print && | |
select undef, undef, undef, ($start + $sleepPerLine * $. - Time::HiRes::time) | |
while <> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment