I am brand spanking new to Perl and this is my first script ever, please go easy on me. So this is my code here:

#Author: Matt Pawlaczyk #Date: 1-6-2017 #Desc: This script takes in a URL and continuosly pings it. The IP e +quivalent of the hostname is returned # and a message displays to indicate if it is online or not. use strict; use warnings; use 5.010; use Socket; use Net::Ping; #acquire a host to ping from the user print "Enter a website to ping:\n"; my $input = <STDIN>; chomp $input; #get the IP address for the hostname my $address = inet_ntoa(inet_aton($input)); #a ping object is created, the protocol by default is TCP, changed to +icmp my $p = Net::Ping->new("icmp"); #ping the inputted website to see if it is live or not. (we do this 10 + times) print "Attempting to ping $input.....\n"; for(my $i = 1; $i <= 10; $i = $i++){ if ($p->ping($input)) { print "Response from $address succesful\n"; #delay execution by 1 second sleep(1); } else { return undef; print "No response from server, try again.\n"; } } print "Done.";
When I enter in for example, "google.com" It works, the ping is successful and I get the IP for the hostname - life is good. However, when I enter in an invalid URL, I get an error message that I am having trouble making sense of. It says to me:
Use of uninitialized value in subroutine entry at pingTest.pl line 16, + <STDIN> line 1. Bad arg length for Socket::inet_ntoa, length is 0, should be 4 at ping +Test.pl line 16, <STDIN> line 1.
Can anybody help me? I've been searching for about an hour now and cannot come up with an answer to this problem.


In reply to Getting what I seem to believe are error with inet_ntoa(inet_aton()) by mattp341

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.