Below code is the part of the script, in which I am merging files of different directories. After merging I am copying remaining files into final directory.
Merging is working fine but while copying files I am getting
cp: missing destination file operand after `/users/abc/perl_scripts/temp_dir/b.cc'
Try `cp --help' for more information.
sh: line 1: /users/abc/perl_scripts/temp: is a directory
for $k(dir1) {
$flag=0;
for $j(@dir2) {
if("$k" eq "$j") {
&merge_gcov("$UERRC1/$k","$UERRC2/$k","$DATA_DIR/$k");
$flag=1;
last;
}
}
if($flag == 0) {
#print ">>>>>>>>>>>>> cp $UERRC1/$k $DATA_DIR/$k \n";
'cp $UERRC1/$k,$DATA_DIR`;
}
}
Can anybody help me to resolve this…
Whenever you are using system calls you are most likely doing something redundant, and it certainly is redundant in this case. Perl is very capable of copying files. I recommend the
File::Copymodule, which is a core module in perl 5. Using it is simple:Also, instead of looping over all the file names in
@dir2and see if the name matches the one in$k, why not just check if the file exists in the other directory? E.g.The documentation for the file test
-eis found inperldoc -f "-X"You really should use variable names that are more appropriate. It will make your code more readable and much easier to maintain and debug.
Also…
Before you do anything else, you should add the following two lines to your script and fix the errors that undoubtedly appear:
strictwill force you to declare all variables (typically withmy $foo) which will remove hard to detect bugs due to typos in variable names. The error message will read “Global symbol $foo requires explicit package name …”.warningswill give you information about things that you are doing wrong. This is a good thing.