perl File::Copy mkpath出现“undefined subroutine”错误

wpx232ag  于 2023-06-06  发布在  Perl
关注(0)|答案(2)|浏览(653)

在这个例程的第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$
4sup72z8

4sup72z81#

File::Copy没有mkpath,但File::Path有。
变更:

use File::Copy;

致:

use File::Path;
i7uq4tfw

i7uq4tfw2#

文件::是否复制自动导出mkpath?或者你需要两者之一

use File::Copy qw/ mkpath /;

或者称之为

File::Copy::mkpath()

相关问题