#!/usr/bin/env perl use strict; use warnings; # use Getopt::Std; use Time::HiRes qw(gettimeofday); $|++; use vars qw( $RATE $START $TOTAL $WAIT ); # $RATE = 4096; # bytes / second # $RATE = 1024; # bytes / second $RATE = 1024 * 300 / 8; # 300 Kbps - a decent default $WAIT = 0.1; # How long to wait between checks? $START = gettimeofday; $TOTAL = 0; while (<>) { while ($TOTAL > (gettimeofday - $START) * $RATE) { sleep $WAIT } my @chars = (split('', $_)); $TOTAL += scalar @chars; print; } # This isn't really good enough, but it's a nice start. I should do # something to a) actually read in the appropriate number of bits instead # of line-by-line, b) rate-limit by more than just the number of seconds # involved, and c) use the command-line to determine what speed we should # limit ourselves to.