1

I keep on getting errors on this routine for line 51 where I used mkpath. I tried putting File::Copy at the top of the subroutine (line 38), but I still get the error.

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;
    }
  }
}

and this is the result:

/production/web/users/etc-users1 found. Performing backup.
/production/archive/2013Nov19/webstart
Undefined subroutine &main::mkpath called at ./testbackup.pl.seco line 51.

The module is on the host:

bash-3.00$ perldoc -l File::Copy
/usr/local/perl5.8.8/lib/5.8.8/File/Copy.pm
bash-3.00$
1
  • Please always use strict Commented Nov 19, 2013 at 22:18

2 Answers 2

2

File::Copy does not have mkpath, but File::Path does.

Change:

use File::Copy;

to:

use File::Path;
Sign up to request clarification or add additional context in comments.

1 Comment

actually that worked - i thought that the mkdir was under the File::Copy
1

Does File::Copy autoexport mkpath? Or maybe you need either

use File::Copy qw/ mkpath /;

or to call it as

File::Copy::mkpath()

1 Comment

File::Copy does not have mkpath, but File::Path does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.