magnus has asked for the wisdom of the Perl Monks concerning the following question:

i was trying to use the Net::Ping; module, but when i create the object like so: $host = Net::Ping->new(); (after use Net:Ping; has been declared, of course) i get the following error message when the code compiles: Can't locate object method "new" via package "Net::Ping" in myprogram at line 12. any ideas what might be the problem? the module Net::Ping, by the way... thanks magnus

Replies are listed 'Best First'.
Re: Problems with Ping
by davorg (Chancellor) on Feb 07, 2001 at 17:34 UTC

    Having discussed this in the CB with magnus it seems that he has a rather old version of Net::Ping (v1.01). This version has a functional interface and therefore doesn't have a new method.

    The solution is therefore to download the most recent (but still four years old!) version from CPAN (http://search.cpan.org/search?dist=Net-Ping).

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: Problems with Ping
by davorg (Chancellor) on Feb 07, 2001 at 16:38 UTC

    Here's a simple example of using Net::Ping, perhaps it will help you find your problem.

    #!/usr/bin/perl -w use strict; use Net::Ping; my $host = shift or die "No host specified.\n"; my $p = Net::Ping->new; my $res = $p->ping($host); die "Unknown host $host\n" unless defined $res; print "$host is ", $res ? 'alive' : 'dead', "\n";
    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      i have run this program exactly as you've typed it...

      i get the same error:

       Can't locate object method "new" via package "Net::Ping" at ...

      could there be something wrong with the module?

      magnus here is the exact code block:
      (imagine, if you will, Net::Ping has already been called)

      sub reachable { (@machines_to_ping) = @_; $host = Net::Ping->new(); foreach (@machines_to_ping){ $reachable = $host->ping($_); if ($reach == 1){ print "$_ reachable\n"; } else { print "$_ not reachable\n"; } } }
      hopefully this helps...
Re: Problems with Ping
by cajun (Chaplain) on Feb 07, 2001 at 16:29 UTC
    Since you posted no code, I (and others) may not be able to help you very much.

    Try this, add:

    use diagnostics;

    This will at least give you more verbose error messages that might be easier to understand.