如何将系统日期附加到 perl 中的文件名?
由于我对 perl 编程非常陌生,你能给我一个上面查询的简单例子吗?
这可能会帮助你!
#!/usr/bin/perl
my $date=`date +%Y%m%d`;
chomp($date);
my $source_file="/tmp/fileName_.tgz";
my $destination_file="/misc/fileName_" . $date . ".tgz";
print "$source_file\n";
print "$destination_file\n";
system("sudo mv /tmp/fileName_.tgz /misc/fileName_$date.tgz");
或试试这个
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
my $out = "$dir/$host-$mday-$mon-$year"
或者这个
# grab the current time
my @now = localtime();
# rearrange the following to suit your stamping needs.
# it currently generates YYYYMMDDhhmmss
my $timeStamp = sprintf("%04d%02d%02d%02d%02d%02d",
$now[5]+1900, $now[4]+1, $now[3],
$now[2], $now[1], $now[0]);
# insert stamp into constant portion of file name.
# the constant portion of the name could be included
# in the sprintf() above.
my $fileName = "File$timeStamp.log";