in reply to Re: gethostbyname bug?
in thread gethostbyname bug?

so do the parens make the difference? (silly question, but i've had issues w/ parens and precedence before).

w/out divulging the actual hostnames, here's what i've gotten:

my $ip = gethostbyname foo.bar.net; print $ip;

gives me back 'foo.bar.net'

UPDATE: now it's working. i don't get it. i've been agonizing over this for hours (and all my previous attempts have never worked.)

Replies are listed 'Best First'.
RE: RE: Re: gethostbyname bug?
by Nooks (Monk) on Sep 11, 2000 at 02:46 UTC
    You were probably doing something like this:
    my ($ip) = gethostbyname("slashdot.org");

    In that code, $ip is in a list, and the statement is in list context, so the statement is equivalent to:

    my ($ip, undef, undef, undef, undef) = gethostbyname("slashdot.org");

    which will put the name in returned from gethostbyname in $ip.

    Aside: This is the reason I rail against unnecessary parenthisation in perl programs---there can be nasty context bugs until you get used to it.

      actually, i wasn't. the code i posted was what i was using. i completely understand what the extra parens would have done (forcing list context, then the first element of that list would be returned).
        geektron wrote:
        actually, i wasn't. the code i posted was what i was using. i completely understand what the extra parens would have done (forcing list context, then the first element of that list would be returned).

        Fine, if you say that's what you were using, that's what you were using. I suggested it because you displayed a bit of uncertainty about what parens did in one of the first answers, because it explained exactly what you'd been seeing, and because I've seen other Perl hackers make the same mistake, and have made it myself.

        Do you have a better suggestion for the behaviour you saw?