You did not chomp your input, so $url contains a new line if you don't run the script with the url on the command line. If you do run it on the command line, the diamond operator actually is looking for file names. By default Net::Ping attempts to establish a connection to the remote host's echo port via TCP, which may not be what you expect, since normal OS ping is an ICMP ping. If you want this behavior, 'icmp' has to be passed to the Net::Ping constructor.

So this works:
#!/usr/bin/env perl use Net::Ping; $url = <>; chomp $url; $p = Net::Ping->new('icmp'); if ($p->ping($url)) { print "working"; } else {print "not working"; }
~$ cat text yahoo.com
And finally the script is ran like this: sudo ./t1.pl text

In reply to Re: Net::Ping blowed my mind by trippledubs
in thread Net::Ping blowed my mind by jack298

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.