my $alive = ping(host => $server);
In a double quoted string, \$ is just escaping the dollar sign, while you want to interpolate the value of $server. And since there is nothing else in the string but $server, might as well skip the interpolation, and just pass the value to ping.
-- Dan | [reply] [d/l] [select] |
What operating system are you running this code on? The module says it is still in alpha stage on CPAN, and for Windows systems, it was only tested on 98. I ran the following on Windows 2000, using ActiveState 5.6.1 build 632: #!C:\perl\bin\perl
use strict;
use warnings;
use Net::Ping::External qw(ping);
print ping(host=>"yahoo.com"), " | ", ping(host=>"wayfakehostname.com"
+);
And received the following output:
C:\Documents and Settings\marc>perl test.pl
0 | 0
On my system ping() is returning 0 for both valid and invalid hostnames (unless it didn't correctly perform the ping, I haven't checked the internals yet), which is why nothing is printing out when I run your code, either. Try playing around with the module a bit more, perhaps your output is similar (and/or perhaps you're using ActivePerl and their port is broken).
Update: There *is* a small bug in the _ping_win32() function of Net::Ping::External (at least the version available through PPM for ActiveState). I changed the last two lines of my own copy from this:
return 1 if $result =~ /time?\d*ms/;
return 0;
to this:return $result =~ /time=\d+ms/?1:0;
and now it works fine for me. I should probably email the author with that bugfix, perhaps it only is affected in 2k, but I suspect not, the time? will positively match, then because he's missing the '=', the rest fails. I can't imagine that 98's ping prints 'time49ms'.
oh, and modifying it using fglock's and zigdon's comments, it works like you want it to :) | [reply] [d/l] [select] |
BTW, it's better to use chomp instead of
chop.
chomp only eats newlines.
| [reply] [d/l] [select] |
Oh, well...
I've tested Net::Ping::External module and the patch by charnos
Make sure your Win machine has the SO in English
if don't, /time/ match fails and you obtain that any host is dead...
Hopes
perl -le '$_=$,=q,\,@4O,,s,^$,$\,,s,s,^,b9,s,$_^=q,$\^-]!,,print'
| [reply] [d/l] [select] |