http://qs1969.pair.com?node_id=1192270


in reply to Re: How to Prepending a timestamp to each line of output from a command
in thread How to Prepending a timestamp to each line of output from a command

This code is magic. I am trying to implement in my program but fail due to little understanding.

#!/usr/bin/env perl use warnings; use strict; use IO::Select; use Time::HiRes qw/ gettimeofday tv_interval /; my @abc = ("a", "b", "c", "d", "e"); for my $v(@abc) { my $sel = IO::Select->new($v); $|=1; my $t0 = [gettimeofday]; while (1) { my $line; if ($sel->can_read(.1)) { defined( $line = $v ) or last } printf "%7.3f | %s", tv_interval($t0), $line//"\r"; $t0 = [gettimeofday] if defined $line; } sleep 1; }

Is this possible to make it a subroutine and call it by default in all STDOUT?