注意:这是一个测试Perl代码来检查是否有效。Perl不会继续
我有问题,我的Perl脚本,我知道有加入
print "Your server is not ok, please check!\n";
die "- Server is not ok!\n";
但停在die "- Server is not ok!\n";
后,我的项目是为一个解决方案继续脚本,我使用的打印显示,如果作品。
继承人的代码
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new(timeout => 1);
$ua->agent("007");
my $req = HTTP::Request->new(GET => 'http://www.google.com.ph/');
my $res;
for (1 .. 10) {
$res = $ua->request($req);
if ($res->is_success) {
print "+ Server is ok!\n";
}
else {
die "- Server is not ok!\n"; # I want to stop if server is not ok and print last code. Or other solution to stop instead of using die.
}
sleep 1;
}
print "Your server is not ok, please check!\n"; # Why this print not showing if stop in "- Server is not ok!\n"?
见图片...
其他解决方案停止?使用die
继续执行perl脚本。
我希望有人会解决这个小问题,谢谢你的回复!
你究竟想要达到什么目的?输出看起来是正确的。 'die'终止程序,而不是循环。有什么问题? – Arc676
停止'HTTP :: Request'并打印最后一个的其他方法。 –
如果你想跳出循环,使用'last;'。 – Ryan