Skip to content

Instantly share code, notes, and snippets.

@liweitianux
Last active February 21, 2024 12:05
Show Gist options
  • Save liweitianux/0f6e9aa2b3fec01371861001d6c59fca to your computer and use it in GitHub Desktop.
Save liweitianux/0f6e9aa2b3fec01371861001d6c59fca to your computer and use it in GitHub Desktop.
Print lines at particular speed (line/sec)
#!/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