develooper Front page | perl.beginners | Postings from February 2002

Re: retrieving info from function

Thread Previous
From:
Brett W. McCoy
Date:
February 7, 2002 12:26
Subject:
Re: retrieving info from function
Message ID:
Pine.LNX.4.43.0202071529350.30587-100000@chapelperilous.net
On Thu, 7 Feb 2002, Jesse Ahrens wrote:

> The gethostbyname() function returns 5 variables, the last on addrs is an
> array. How do I specify the function to only return that array rather than
> the 4 strings and 1 array?

gethostbyname() returns a list.  You can coerce that list to become an
array and then just grab that last element:

my @addresses = (gethostbyname($hostname))[4];

foreach (@addresses) {
	print join('.', unpack('C4',$_)), "\n";
}

-- Brett

                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
	Why are you doing this to me?
	Because knowledge is torture, and there must be awareness before
there is change.
		-- Jim Starlin, "Captain Marvel", #29


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About