One wierd behaviour I am observing -- in a perl script , I checked wether a directory exists or not, if it exists - it copies a file to that directory, if it doesnt -then the directory is created followed by the file copy
When I go and check the file manually, the file is present . but when I run the same script again to copy another file using the same process as above, I see that the previous files arent present. For a confirmation , I performed a directory read in the script , it said that dir is empty.
Can anyone please help me in understanding
Please find below a code :
if (-d "/home/foo") {
print "the directory is already created \n";
$i=0;
opendir(DIR, "/home/foo") or die "Cant open /home/foo: $!\n";
@list = readdir(DIR);
foreach $line(@list) {
unless ($line =~ /^[.][.]?\z/) {
$i++;
}
}
if ($i != 0) { print "There is Stuff in here!"; }
else { print "This Dir is Empty!"; }
closedir(DIR);
}
else {
&runcond("mkdir /home/foo");
}
`cp $file /home/foo`; #Copying a file $file in the directory
`cp $file /home/foo`;
您尚未定义$file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.