Anant Gupta wrote:
I wrote

#!usr/bin/perl
use Socket;
use constant ADDR => 'www.google.com';
my $name=shift || ADDR;
$packed=gethostbyname($name);
$dotted-inet_ntoa($packed);
print "DOtted Address is $packed";

but it is showing an error
"Bad argument length for Socket length in inet_ntoa" ???

perldoc -f gethostbyname

[ SNIP ]

        In the opposite way, to resolve a hostname to the IP address you
        can write this:

            use Socket;
            $packed_ip = gethostbyname("www.perl.org");
            if (defined $packed_ip) {
                $ip_address = inet_ntoa($packed_ip);
            }

        Make sure <gethostbyname()> is called in SCALAR context and that
        its return value is checked for definedness.
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


So:

$packed=gethostbyname($name);

should be something like this instead:

defined( my $packed = gethostbyname( $name ) ) or die "Cannot find address for '$name'";




John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
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