我正在尝试使用File :: Copy将一些文件从一个网络共享复制到另一个网络共享.
这是我的代码:
#!C:/strawberry/perl/bin/perl.exe
use File::Copy;
print "Content-type: text/html\n\n";
print "<H1>Hello World</H1>\n";
copy("s:\\nl\\cover\\config.jsp", "s:\\temp\\config.jsp")
or die "File cannot be copied.";
print "this is not displayed";
Run Code Online (Sandbox Code Playgroud)
为什么'die'消息无法呈现?
如果您在Web服务器上运行这个(我无法想象,为什么您要发送一个"Content-Type"
报头),您使用发出任何错误消息die
,并warn
会到服务器的错误日志.
此外,如果您将其作为CGI调用,请注意您声称您正在发送HTML而不是发送HTML,因此您在撒谎.
特别是如果你刚开始学习Perl的,你应该作出努力,以点所有的我秒和跨越所有牛逼 S:
#!C:/strawberry/perl/bin/perl.exe
use strict; # every time
use warnings; # every time
use CGI qw(:cgi);
use CGI::Carp qw(fatalsToBrowser); # only during debugging
use File::Copy;
use File::Spec::Functions qw(catfile);
$| = 1;
# prefer portable ways of dealing with filenames
# see http://search.cpan.org/perldoc/File::Spec
my $source = catfile(qw(S: n1 cover config.jsp));
my $target = catfile(qw(S: temp config.jsp));
print header('text/plain');
if ( copy $source => $target ) {
print "'$source' was copied to '$target'\n";
}
else {
print "'$source' was not copied to '$target'\n";
# you can use die if you want the error message to
# go to the error log and an "Internal Server Error"
# to be shown to the web site visitor.
# die "'$source' was not copied to '$target'\n";
}
Run Code Online (Sandbox Code Playgroud)
有关面向功能的界面导入列表,请参阅CGI.