Date and time log file

Hi,

I wrote a small perl script in unix that searches in a file and saves some information in a separate file. Since this is a log file, I would like to have the date added to file name. I have no idea where to start.
output:
log_010907.txt

thanks
ken

perldoc -q open
perldoc -f localtime

You can save the output of the date command (date "+%d%m%y") to a variable and append it to your log file name.

Hope this is what you were looking for.

you can do--

str1=`date "+%d%m%y"`

and use this variable in the logfilename.
log1_$str1.txt

Thanks
Namish

the OP has a perl script.

OP = operator ?

here is what I have from what you told me.

#!/usr/bin/perl -w
use Time::localtime;
 
str1=`date "+%d%m%y"`;
open (FILE,"<traffic_TLG");

foreach $line (<FILE>) {
  if ($line =~ m/beth/) {
  open (FILE, ">>log_$str1.txt");
  
    @items =  split(",",$line);
    print FILE $items[4], ",", $items[10], ",", $items[15], ";" . "\n";

	close(FILE); 
  }

}

close (FILE); 

I get a cannot modify a constant scalar error when I run it. Otherwise the program works. why does'n it work?

there's no need to use Time::localtime. from perldoc -f localtime

 
#  0    1    2     3     4    5     6     7     8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

from that, you can assign your date variable. there's no need to call external date command from the shell. for more information, read the rest of perldoc -f localtime.

put all your open() and close() commands outside the for loop. Use a different file handler, don't name both of them FILE !..

what is the difference between Time::localtime. and localtime(time )
?

ken

i only mentioned because i don't see it being used anywhere..so i suggested you just use the inbuilt localtime() . you can use it if you want.