Home: Perl Programming Help: Intermediate:
date stamps on files


Jun 19, 2005, 2:13 PM

Views: 1458
date stamps on files


I am just having problems here with my little code down below..what iam trying is do is create a new file for logs to be stored at when the date changes and that should be done daily hence i will have a file date stamp on each seperate file..i tried the below code but it just doesnt creates a new file for each date change..it jst keeps writing to the same file with the old date stamp..

any ideas?

my @t = localtime(time);

my $fileTimeStamp = ($t[5]+1900) . "-" . ($t[4]+1) . "-" . $t[3];

open(OUTPUT_FILE, ">>/data2/logs/t5/$hostname\_$port\_$fileTimeStamp.$type");

select OUTPUT_FILE; $| = 1;

my $line;

while (<SOCKET>)
my @ct = localtime(time()); # current localtime

my $currentTimeStamp = ($t[5]+1900) . "-" . ($t[4]+1) . "-" . $t[3];

if($fileTimeStamp ne $currentTimeStamp)

$fileTimeStamp = $currentTimeStamp; # set file stamp to current for use in open and later checks
close OUTPUT_FILE || warn($!);
open(OUTPUT_FILE,">>/data2/logs/t5/$hostname\_$port\_$fileTimeStamp.$type") || die($!);