Feb 27, 2013, 10:23 AM
Post #1 of 3
I am trying to run a simple script that will copy existing files and append with a date stamp. I want to keep the original (why I am not using 'move').
Problem using File::Copy to create archive files
If I run the script with an extension, it works, if I try to pass a scalar value, it does not. (takes scalar as literal).
The first file copies as file1.archive while the second file copies as file2.$now_string
Code with both examples:
use POSIX qw(strftime);
my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
copy('/tmp/file1','/tmp/scripttest/file1.archive') or warn "Archive Copy failed: $!"; #This works
copy('/tmp/file2','/tmp/scripttest/file2.$now_string') or warn "Archive Copy failed: $!"; #This does not