in reply to Could not create socket: Bad file number

AFAIK, IO::Socket::INET->new() does not set $!, which would mean the error message you get from $! is undetermined (I get 'invalid argument', but YMMV)

Secondly, unless the machine you're running this on really has the hostname 'myhost' it will fail.

Removing the LocalHost parameter or setting the value to 'localhost' works for me.

Replies are listed 'Best First'.
Re^2: Could not create socket: Bad file number
by ikegami (Patriarch) on Aug 30, 2007 at 21:20 UTC

    AFAIK, IO::Socket::INET->new() does not set $!,

    Quite the opposite. It's the only module I know that does set $! even for errors not originating from system calls. That could account for the error message mismatch.

      Well, if it does, I can't find any mention of that behaviour in the documentation. The only thing that I can find that even mentions $! is IO::Handle's blocking() method.

      update: however, reading the source code shows that you're right. But I can't really say if it will always produce a useful error in $! though. Sometimes it sets $! to $EINVAL, other times it just passes on $! from functions that may or may not set $! on failure. (And some build in functions that do set $! are not documented as such in the perldocs, but that's another story)

Re^2: Could not create socket: Bad file number
by pilcrow (Sexton) on Aug 31, 2007 at 18:56 UTC
    AFAIK, IO::Socket::INET->new() does not set $!

    It's poorly documented, but IO::Socket and its INET subclass put their informative errors into $@. So, the OP wants something like:

    my $s = IO::Socket::INET->new(...) or die "new sock: $@\n";

    -pilcrow