sekharsomu has asked for the wisdom of the Perl Monks concerning the following question:

i am trying to copy only files from specfic source to specfic destination (into sub folder of source ) with the date appended here is what i have tried:
use File::Copy; $dir="/tmp/test2/magic/"; opendir(DIR, $dir) or die "can't opendir $dir: $! \n"; @files=readdir(DIR); closedir DIR; # Get currect date/time my @date = (localtime)[5,4,3,2,1,0]; $date[0] +=1900; ++$date[1]; $date_string = sprintf('%04d%02d%02d',@date[0,1,2]); foreach $file (@files) { if (-f "$dir$file") { $moveloc="/tmp/test2/magic/backup/$file.$date_string"; $old = "$dir$file $new = "$moveloc"; copy($old, $new) or die "Copy Faild: $!";
My machine is AIX5.1 when i try to execute i get the following errors:
./testrenp11122010b ./testrenp11122010b: use: not found. ./testrenp11122010b[3]: =/tmp/test2/magic/: not found. ./testrenp11122010b[4]: 0403-057 Syntax error at line 4 : `(' is not e +xpected.
when i change directory the path is actually present, but error shows not found , i am actually getting started with perl i have no idea of other error please correct me

Replies are listed 'Best First'.
Re: copy contents appending date
by jwkrahn (Abbot) on Nov 13, 2010 at 07:15 UTC

    It looks like the shell is executing your program instead of perl.    You should begin your Perl program with these three lines:

    #!/usr/bin/perl use warnings; use strict;
Re: copy contents appending date
by kcott (Archbishop) on Nov 13, 2010 at 09:24 UTC

    From the commandline, which perl should provide the correct path for #!...

    You should also be able to run your script with: perl ./testrenp11122010b

    Regardless of how you call your script, still add the strict and warnings lines as recommended by jwkrahn.

    -- Ken

Re: copy contents appending date
by wwe (Friar) on Nov 15, 2010 at 10:32 UTC
    one addition to the previous comments: File::Copy can copy files between existing directories only. If you destination directory doesn't exist now or you want to copy file somewhere in a directory tree take a look at File::Copy::Recursive which can create missing directories.