簡體   English   中英

perl File :: Copy mkpath錯誤“未定義的子例程”

[英]error “undefined subroutine” with perl File::Copy mkpath

我在使用mkpath的第51行的例程中不斷出錯-我嘗試將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$

File :: Copy是否自動導出mkpath? 或者也許您需要

use File::Copy qw/ mkpath /;

或稱它為

File::Copy::mkpath()

File :: Copy沒有mkpath ,但是File :: Path有。

更改:

use File::Copy;

至:

use File::Path;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM