I am trying to move files and rename them with a date-time stamp I generate. I have a survey and my perl script processes the POST query string. Once I have the query string, I am using XML::Simple to get the stored results, update them, then write them back out.
I don't want to write to the the file I just read from in case there is a problem. I want to back it up. But it doesn't work. Any time I try to add a formatted date time stamp to the name, the operation fails.
Here is the code:
#! perl
use File::Copy;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(time);
$stamp = sprintf ("%4d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
$old_name = 'result.xml';
$new_name = 'results ' . $stamp . '.xml';
copy($old_name, $new_name) or print debug "Error copying.";
The following code does work however:
#! perl
use File::Copy;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(time);
$stamp = sprintf ("%4d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
$old_name = 'result.xml';
$new_name = 'new_results.xml';
copy($old_name, $new_name) or print debug "Error copying.";
Any ideas?
And no this isn't a homework assignment. It's a favor for my mom.