[rochester-pm-list] Net::Ping

Brian Mathis bmathis at directedge.com
Wed Feb 10 00:09:06 CST 1999


Well, I finally got a chance to look at this.  Sorry it took so long
:).  
Anyway, terminology is very important.  "If the hostname cannot be
found, or there is a problem with the IP number, undef is returned." 
Don't get "undef" confused with "null", they are very different.  A
variable that is null actually exists but contains a null value.  A
variable that is not defined, or "undef", simply doesn't exist at all. 
(Similar to having an empty bucket, or having no bucket at all)

I suspect that the code is actually working properly, but you are not
testing the values correctly.  Here's my code that seems to work:

    use Net::Ping;
    my $p = Net::Ping->new('tcp', 50);
    my $resp = $p->ping( $ARGV[0] );

    if( defined $resp ) {
       print "ok\n";
    } else {
       print "not ok\n";
    }                 

Note that checking for "defined" is different from doing a
    if($var == '') { }

However, I also get a 0 returned as the value, even when the host is
reachable.  I don't know why this is.  It seems sufficient to check if
the variable is defined or not.  It's late and I can't think about this
anymore right now.. I'll see what other people have to say tomorrow.

Brian

---------------------------------------------------
Shawn Porter wrote:
> 
> Has anybody else ever used Net::Ping.  I was using it the other day and it
> wasn't working according to its documentation.
> 
> Here's a snippet:
> 
>         use Net::Ping;
>         my $p = Net::Ping->new(tcp, 50);
>         my $resp = $p->ping($hostname);
> 
> When I do this, I get a '0' in $resp if I can contact the host and a ''
> (null) if I can't contact the host.  (Changing the timeout doesn't affect
> it.)  According to the docs, I should get a '1' if it is reachable, a '0'
> if it is not, and '' (null) if "the hostname cannot be found or there is a
> problem with the IP number."  No matter what I do, it never returns a '1'.
> 
> (Perl 5.004_04 tested on Linux 2.0.36 and Digital OSF1 V4.0.)
> 
> Any ideas?
> 
> --
> Shawn Porter
> http://www.rit.net/sporter
> sporter at rit.net



More information about the Rochester-pm mailing list