perlquestion
jnarayan81
<p>
How to pre-pending a timestamp to each line of output from a command?
Something like this https://i.stack.imgur.com/3EIM1.gif
</p>
<p>
I tried the following code, but fail to achieve it :(
</p>
<code>
use strict;
use warnings;
use POSIX q(strftime);
my @abc = ("a", "b", "c", "d", "e");
my $time=POSIX::strftime('%a, %d %b %Y %T %z', localtime);
foreach (@abc) { print "[$time]\t$_\n"; sleep 5;}
</code>