in reply to Re^4: Append the timestamp before and after the data in the logfile
in thread Append the timestamp before and after the data in the logfile

Honestly, I think you are going about this the wrong way. You really should be looking at something like File::Log

Failing that, you could do something like this:

#!/usr/bin/perl -w use strict; use POSIX qw(strftime); my $start = time(); print "Started at ", (strftime "%a %b %e %H:%M:%S %Y", localtime($star +t)), "\n"; for (1 .. 5) { print "Logging some stuff...\n"; sleep 1; } my $end = time(); print "Ended at ", (strftime "%a %b %e %H:%M:%S %Y", localtime($end)), + "\n"; print "Total run time:", $end-$start, " seconds\n";

Which when run, gives you:

Started at Thu Dec 22 14:59:20 2005 Logging some stuff... Logging some stuff... Logging some stuff... Logging some stuff... Logging some stuff... Ended at Thu Dec 22 14:59:25 2005 Total run time:5 seconds

Then you simply redirect that to your logfile in the same way as you originally did.

Replies are listed 'Best First'.
Re^6: Append the timestamp before and after the data in the logfile
by blazar (Canon) on Dec 27, 2005 at 13:55 UTC
    print "Started at ", (strftime "%a %b %e %H:%M:%S %Y", localtime($star +t)), "\n";

    Also

    scalar localtime

    (See what localtime does in scalar context) - Oh, this bad habit of Perl having the right dwimmery built in!! ;-)