On Sun, Aug 23, 2009 at 21:06, fzz<fanzhenzh...@gmail.com> wrote:
> hi all        I installed Net::Oping module. I run it ,but I can't get right
> values . Please give me some light. Thanks in advance.
> I write these code:
>
> #!/usr/bin/perl
>

You should really say the following here:

use strict;
use warnings;

>  use Net::Oping ();
>
>  my $obj = Net::Oping->new ();
>  $obj->host_add (qw(www.example.org));
>
>  my $ret = $obj->ping ();
>  print "Latency to `one' is " . $ret->{'www.example.org'} . "\n";

There is no reason to use the concatenation operator here, just use
interpolation:

print "Latency to `one' is $ret->{'www.example.org'}\n";

>
>  my $my_ttl=$obj->get_dropped();
>  print 'my ttl is '.$my_ttl."\n";
>  my $my_drop=$obj->get_dropped();
>  print 'my_drop '.$my_drop."\n";

You are calling get_dropped twice, but referring to the result as
$my_ttl once.  I am betting you meant to call get_recv_ttl instead.
Also, the documentation claims that the return value for get_dropped
and get_recv_ttl is a hashref (which is consistent with what you got
in your print statements).  Hashrefs are data structures and cannot be
printed out just by printing them.  The simplest way to print it would
be to say

my $ttl = $obj->get_recv_ttl;
print "time to live:\n";
for my $key (%$ttl) {
    print "\t$key => $ttl->{$key}\n";
}

my $drop = $obj->get_dropped;
print "drops:\n";
for my $key (%$drop) {
    print "\t$key => $drop->{$key}\n";
}

Warning, the code above is untested.  I do not have the requisite the
library to install the Perl Module.


>  my $my_err_msg=$obj->get_error();
>  print 'my_error: '.$my_err_msg."\n";

There is no reason to use the concatenation operator here.  Just use
interpolation:

print "my_error: $my_err_msg\n";





-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to