[root@jhoa 2015]# cat ping_dns.pl
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::Ping;
my @array=( "mbank.app.cz"
);
while (1==1){
my $CurrTime = time2iso(time());
foreach $host (@array){
$p = Net::Ping->new("icmp");
open (A, ">>ping.log");
(
print A ("$CurrTime---$host is active.
")
) if $p->ping($host,5);
open (B ,">>ping.log");
(
print B ("$CurrTime---$host is lost.
") ,
print "xxxxxx
"
) unless $p->ping($host,5);
$p->close();
sleep(5)
}}
[root@jhoa 2015]# perl ping_dns.pl
xxxxxx
xxxxxx
xxxxxx
xxxxxx
1[root@jhoa 2015]# tail -10 ping.log
12015-02-26 11:48:58---mbank.app.cz is lost.
12015-02-26 11:49:03---mbank.app.cz is lost.
12015-02-26 12:23:36---mbank.app.cz is lost.
12015-02-26 12:23:41---mbank.app.cz is lost.
12015-02-26 12:23:46---mbank.app.cz is lost.
12015-02-26 12:24:11---mbank.app.cz is lost.
12015-02-26 12:24:16---mbank.app.cz is lost.
12015-02-26 12:24:21---mbank.app.cz is lost.
12015-02-26 12:24:26---mbank.app.cz is lost.
为啥前面会打印出1呢? 因为1是print 的返回值
[root@jhoa 2015]# cat a3.pl
(print "a",print "b");
[root@jhoa 2015]# perl a3.pl
ba1[root@jhoa 2015]#
[root@jhoa 2015]# cat a3.pl
(print "a", "b");
[root@jhoa 2015]# perl a3.pl
ab[root@jhoa 2015]#