Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

RE: RE: Re: gethostbyname bug?

by Nooks (Monk)
on Sep 11, 2000 at 02:46 UTC ( [id://31821]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
RE: RE: RE: Re: gethostbyname bug?
by geektron (Curate) on Sep 12, 2000 at 02:13 UTC
    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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://31821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-19 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found