[Gllug] Imposing a delay in a pipeline

Richard Huxton dev at archonet.com
Tue Apr 13 15:07:55 UTC 2010


On 13/04/10 15:56, Richard Huxton wrote:
>
> perl -e 'sleep 5; print while (<>)'

Actually, that's not going to work either, is it?

You'd need something that timestamps the lines and lets them out more 
flexibly. My mad perl skillz fail me and I'm reduced to using more than 
one line:

#!/usr/bin/perl

my %buckets;

sub delayedprint {
     $SIG{ALRM} = \&delayedprint;
     $buckets{time()} && print $buckets{time()};
     alarm(1);
}

$SIG{ALRM} = \&delayedprint;
alarm(1);

while (<>) {
     $buckets{time() + 5} .= $_;
}


-- 
   Richard Huxton
   Archonet Ltd
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list