Hi,

I made the perl script and I print out with Txt file.
For EX :

Open (OUTPUT,">data.txt"));

out put

data.txt

But I hope at the day that I run the script, the day will be labeled with the name file. Like the name below:

20110919data.txt

Could you please show me how to solve this problem.
Thank you very much.

use the 'localtime' function and get the date format.

$filename='data.txt';

my ($sec,$min,$hour,$mday,$mon,$year)=localtime();
$year+=1900;
$mon=sprintf("%02d", $mon+1);
$mday=sprintf("%02d", $mday);

my $today_file = "$year$mon$mday"."$filename";

print $today_file;

Read More...

perldoc -f localtime

Thank you very much for your help.
I ask you small question.
how can I have the result 20110919baselist.txt if I use below code

open(BASE,">baselist.txt");

        for (my $i = 0; $i < $num; $i++){
             $base=substr($ref,$posi[$i]-1, 3);	     
              print $base;
              print BASE $base."\n\n";
	}
        close(BASE);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.