Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I can't get the following script to work. I'm probably overlooking something super obvious, but I can't grok it this morning.
What I want to do is have an ongoing log file, where I can enter a comment, and have that comment timestamped. Any tips appreciated.
use strict; use warnings; use Data::Dumper; my ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst)=localtime(time); my $table; my $log = 'log_file.txt'; open my $fh, '>>', $log or die "Can't open $log : $!"; while (<$fh>) { my $comment = <STDIN>; chomp $comment; printf "%4d-%02d-%02d %02d:%02d:%02d\t", $year+1900,$mon+1,$mday,$hour,$min,$sec; print $comment . "\n"; printf $fh "%4d-%02d-%02d %02d:%02d:%02d\t", $year+1900,$mon+1,$mday,$hour,$min,$sec; print $fh $comment . "\n"; } close $fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: script for adding timestamp to stdin
by Old_Gray_Bear (Bishop) on Jun 02, 2010 at 17:21 UTC | |
|
Re: script for adding timestamp to stdin
by vtheron (Novice) on Jun 02, 2010 at 18:10 UTC | |
by Anonymous Monk on Jun 02, 2010 at 18:42 UTC | |
by almut (Canon) on Jun 02, 2010 at 19:10 UTC | |
by Anonymous Monk on Jan 20, 2012 at 15:45 UTC | |
|
Re: script for adding timestamp to stdin
by almut (Canon) on Jun 02, 2010 at 17:33 UTC |