CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Problem using File::Copy to create archive files

 



StarkRavingCalm
User

Feb 27, 2013, 10:23 AM

Post #1 of 3 (409 views)
Problem using File::Copy to create archive files Can't Post

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').

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:

Code
#!/usr/bin/perl 
use warnings;
use strict;
use File::Copy;
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


FishMonger
Veteran / Moderator

Feb 27, 2013, 10:37 AM

Post #2 of 3 (407 views)
Re: [StarkRavingCalm] Problem using File::Copy to create archive files [In reply to] Can't Post

Use double quotes when you want/need to interpolate vars.

change:

Code
copy('/tmp/file2','/tmp/scripttest/file2.$now_string') or warn "Archive Copy failed: $!";


to:

Code
copy('/tmp/file2', "/tmp/scripttest/file2.$now_string") or warn "Archive Copy failed: $!";



StarkRavingCalm
User

Feb 27, 2013, 11:07 AM

Post #3 of 3 (403 views)
Re: [FishMonger] Problem using File::Copy to create archive files [In reply to] Can't Post

Thank you!! That worked!

You always make this seem so easy!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives