【发布时间】:2020-02-12 16:25:06
【问题描述】:
我正在尝试执行一个简单的草莓 perl 脚本进行文件复制,以从最后执行的命令中获取代码。但在所有情况下我都得到 0/success。
来自我的 test.pl 脚本的代码
use File::Copy;
use strict;
use warnings;
my $source_file = "D:\\abc\\def\\in\\test\\test1.csv";
my $target_file = "D:\\abc\\def\\in\\test\\test2.csv";
if ( copy( $source_file, $target_file ) == 0 ) {
print "success";
}
else { print "fail"; }
由于我使用的路径 D:\\abc\\def\\in\\test\\test1.csv 在机器上不存在,所以我预计会失败,但无论我提供什么,我都会成功。
下面的执行和输出:
D:\pet\common\bin\backup>perl test.pl 成功【问题讨论】:
-
这是我的第一篇文章,所以请原谅文章的格式
-
copy在失败时返回假/零(它不像system) -
非常感谢 David O 和 ikegami !它解决了这个问题。
标签: perl error-handling copy file-copying strawberry-perl