我試圖使用perl將這些文件從一個文件夾複製到另一個文件夾。這些文件夾將作爲用戶的輸入傳遞。複製文件時未定義的子程序調用
例子:
First folder : \\filesource\source
Target folder: \\filesource\destination
,但在複製文件時,我得到以下提到的錯誤:
Undefined subroutine &main::Copy called
代碼:
use strict;
use File::Copy;
my $errExitCode_const = 1;
unless(@ARGV == 2){
print "$0 - requires 2 input parameters and only " .
@ARGV ." are being passed. \n$!\n";
exit($errExitCode_const);
}
## Get parameters
my $source_dir = $ARGV[0];
my $dest_dir = $ARGV[1];
## Initiazise Variables
my @files;
my $file_name;
my $filename;
my $dt_stamp;
## Change the directory path.
chdir($source_dir);
# Reads all files from the input directory.
@files = <*>;
foreach $filename(@files) {
$file_name = substr($filename,0,19);
print "\nfile_name:" . $file_name;
if($file_name =~ "PROVIDER_KEY_IN_IGF") {
Copy($file_name,$dest_dir.$file_name)
or die "Failed to copy $file_name :$!\n";
}
#Delete input file #unlink($filename);
} ## End foreach
您是否檢查過[文件::複製](http://perldoc.perl.org/File/Copy.html)?你應該使用'copy($ file_name,$ dest_dir。$ file_name);' – 2014-10-22 11:02:49
'File :: Copy :: copy'也可以做到這一點。 – Sobrique 2014-10-22 14:01:35