#!/usr/bin/perl ############################################################################## ### Configuration ############################################################ ############################################################################## ## Data rate; default to 300kbps our $RATE = 1024 * 300 / 8; ## How long to wait between checks? our $WAIT = 0.1; ############################################################################## ### Declarations ############################################################# ############################################################################## use strict; use warnings; use Time::HiRes qw/gettimeofday/; $|++; # make sure ############################################################################## ### main () ################################################################## ############################################################################## my $start = gettimeofday; my $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.