我继续在第51行的例行程序中遇到错误,我使用了mkpath - 我尝试将File :: Copy放在子程序的顶部(第38行),但仍然出错 -
use warnings;
use DBI;
use File::Copy;
unshift @INC, "/production/lib";
require "config.pl";
$configFile = "/production/cfg/syncUsers.cfg";
readConfig($configFile);
doBackup($prefs{passwdFile});
# generatePasswdFile("tmpusers");
# getUsers($prefs{dbUser}, $prefs{dbPass}, $prefs{dbSid});
# copyPasswdFile($prefs{passwdFile});
# doBackup - backup the existing
sub doBackup {
#use File::Copy;
my (@theMonth, $month, $day, $year) = "";
if (!-e $prefs{passwdFile}) {
print "Password file: $prefs{passwdFile} does not exist. No backup being made.\n";
}
else {
print "$prefs{passwdFile} found. Performing backup.\n";
($mday, $mon, $year) = (localtime(time))[3 .. 5];
@theMonth = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
$month = $theMonth[$mon];
$day = sprintf("%02d", $mday);
$year = sprintf("%04d", $year + 1900);
$backupDir = "$prefs{backupDir}/$year$month$day/webstart";
print "$backupDir\n";
mkpath($backupDir); # Line 51
if (-e "$backupDir") {
move($prefs{passwdFile}, $backupDir);
}
else {
print "The backup directory was not created\n";
}
if (-e "$backupDir/etc-users") {
print "Backup successful. Generating file.\n";
}
else {
print "Backup failed. Exiting.\n";
exit 1;
}
}
}
这就是结果:
/production/web/users/etc-users1 found. Performing backup.
/production/archive/2013Nov19/webstart
Undefined subroutine &main::mkpath called at ./testbackup.pl.seco line 51.
模块在主机上:
bash-3.00$ perldoc -l File::Copy
/usr/local/perl5.8.8/lib/5.8.8/File/Copy.pm
bash-3.00$
答案 0 :(得分:2)
File :: Copy是否自动导出mkpath?或许你需要
use File::Copy qw/ mkpath /;
或将其称为
File::Copy::mkpath()
答案 1 :(得分:2)