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

I'm trying to run an example script out the Perl little black book and its not going very well.
#!/usr/bin/perl use IO::Socket; $socket = IO::Socket::INET->new(Proto => 'udp', peerPort => 4321, peeraddr => localhost); $socket->send('Hello');
I get the following error msg.
send:cannot determine peer address at line 6
I've tried changing peer to local and for the address using the output from hostname --fqdn

Please help!
Thanks
another Newbie

Replies are listed 'Best First'.
Re: what the?
by wog (Curate) on Feb 02, 2002 at 17:38 UTC
    IO::Socket:INET is case-sensitive, so you must use PeerPort and PeerAddr, not peerPort and peeraddr.

    Though, it won't solve your problem in this case, I strongly advise quoting strings and using strict and warnings. It is likely to save you time in the future.

Re: what the?
by data64 (Chaplain) on Feb 02, 2002 at 17:27 UTC

    You probably want to include a

    use strict; use warnings;

    at the top.

    I would guess the problem is that localhost should be enclosed in quotes like "localhost".

    Update: Added working code.

    Below is code that works for me.

    #!/usr/bin/perl.exe use IO::Socket; use strict; use warnings; my $socket; $socket = IO::Socket::INET->new(Proto => 'udp', PeerPort => 80, PeerAddr => "localhost") or die "opening port, $! "; $socket->send("Hello");
Re: what the?
by LukeyBoy (Friar) on Feb 02, 2002 at 17:34 UTC
    Instead of "peeraddr => localhost" you should use:

    $socket = IO::Socket::INET->new(Proto => 'udp', PeerAddr => "localhost:4321");

    That should work.
Re: Problem with example UDP script from Perl Little Black Book
by kyser_sose (Initiate) on Feb 02, 2002 at 23:45 UTC
    Thanks for all the answers :) Using the correct letter casing seemed to fix that particular prob. Thanks agian.