Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by Discipulus (Canon)
on Jun 07, 2017 at 09:20 UTC ( [id://1192257]=note: print w/replies, xml ) Need Help??


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

hello jnarayan81,

First of all you are assigning to $time once, so even if the format will work you'll end with the same time at each print: you must call it at each iteration directly or with a sub.

Second I do not find %a to be valid in the format description, see the following code:

use strict; use warnings; use POSIX q(strftime); my @abc = ("a", "b", "c", "d", "e"); foreach (@abc) { print '[',(strftime '%Y-%m-%d-%H-%M-%S', localtime()) +. "]\t$_\n"; sleep 1;} #output [2017-06-07-11-19-36] a [2017-06-07-11-19-37] b [2017-06-07-11-19-38] c [2017-06-07-11-19-39] d [2017-06-07-11-19-40] e

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1192257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found