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 :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.