cp not coping properly

Hi,

I'm trying to copy the directories from one location(/tmp/source/) to other(/tmp/dest/).
for this I have written a PERL script.
snippet of code

$sourcePath = "/tmp/source";
$destPath = "/tmp/dest";
opendir(DIR, $sourcePath );
while($dir = readdir(DIR))
{
	if($dir ne "." && $dir ne "..")
	{
		$sourceDir = $sourcePath . "/" . $dir;
		$destDir = $destPath . "/" . $dir;
		$cpCMD = "cp -rf $sourceDir $destDir";
                system $cpCMD;

	}
}

For Some directories it is working fine.
But for others the directories are created like /tmp/dest/report1/report1/files instead of /tmp/dest/report1/files.:frowning:

If I'm not clear, Please revert.

can somebody help me?

Thanks in Advance.

Well the sort of issue you may get with cp is when it sees a link, and copies it ...as a directory with all its content etc...

Why not use cpio? or test if dir is a true dir or a symlink...

why cpio? It will copy depending of your options the links as links... (but there are also other commands to choose from)
how?
source= /tmp/source
dest=/tmp/dest

In HPUX...

cd $source;
find . -print|cpio -pduml $dest

This is just one solution, Im sure there are plenty of valid ways to do the same...