in reply to Date and time for log files


my @t = localtime(time);
my ($rf, $td);
$t4++;
$td = (1900 + $t5) . ((length($t4)==1)?(0 . $t4):$t4) . ((length($t3)>1)?$t3:(0 . $t3)) . ((length($t2)==1)?(0 . $t2):$t2) . ((length($t1)>1)?$t1:(0 . $t1)) . ((length($t[0])>1)?$t[0]:(0 . $t[0]));

open(PLOG, ">>/usr/perl_scripts/$td.log");
print PLOG "Hello World";
close(PLOG);
The above sample script will create the log file with date and time.

Replies are listed 'Best First'.
Re^2: Date and time for log files
by graff (Chancellor) on Oct 05, 2007 at 05:16 UTC
    Please put <code> (or <c>) at the beginning of any program code or data, and put </code> (or </c>) at the end of your code or data, when you post.

    Read Writeup Formatting Tips.

    Learn from what other people have posted.

    And please, please, PLEASE use <code> tags when you post code or data (abbreviate them to just "c" if you like, but use these tags).