Meghanand Acharekar <vasco.deb...@gmail.com> asked:

> I am writing a perl script which creates a file (on Linux/UNIX) using
> system's date. 
> e.g. log_2009-07-07.gz
> 
> Here is the code I wrote.
> 
> #!/usr/bin/perl -w

use strict;

> # Prog for demostrating file name concatenations.
> $prefix="log";
> $suffix=".gz";

my $prefix = 'log';
my $suffix = '.gz';

> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);

my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);

> # Time
> $middle=sprintf "%4d-%02d-%02d \n",$year+1900,$mon+1,$mday;

# note no \n here!
my $middle=sprintf "%4d-%02d-%02d",$year+1900,$mon+1,$mday;

> print "My Date : $middle\n";
> $file_name=join("_",$prefix.$middle.$suffix);

my $file_name=join("_", $prefix, $middle, $suffix );

> print "New File name : $file_name \n";

__END__

HTH,
Thomas

Reply via email to