What's going wrong here?

#!/usr/bin/perl5 -w use Net::Ping; my @pinglist = ( "svhappy" ,"w01b0rji" ,"w01b0rji.cube.fred.ch" ,"svmoloch.flur.fred.ch" ,"160.69.125.142" ); $p = Net::Ping->new(); foreach $h (@pinglist) { chomp (my $res = `ping $h`); if ($res) {print "$h \`ping\` OK :\t$res\n"} else {print "$h \`ping\` NOK\n"} if ($p->ping($h)) {print "$h \$p->ping OK\n"} else {print "$h \$p->ping NOK\n"} print "\n"; } $p->close();

...gives following results:

(svmoloch:szhxrv) $ ./test.pl

ping: unknown host svhappy
svhappy `ping` NOK
svhappy $p->ping NOK

ping: unknown host w01b0rji
w01b0rji `ping` NOK
w01b0rji $p->ping NOK

w01b0rji.cube.fred.ch `ping` OK : w01b0rji.cube.fred.ch is alive
w01b0rji.cube.fred.ch $p->ping NOK

svmoloch.flur.fred.ch `ping` OK : svmoloch.flur.fred.ch is alive
svmoloch.flur.fred.ch $p->ping NOK

160.69.125.142 `ping` OK : 160.69.125.142 is alive
160.69.125.142 $p->ping NOK


In reply to Unexpected results from ping by GreyOwl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.