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

Re: retrieving info from function

Thread Previous
Brett W. McCoy
February 7, 2002 12:26
Re: retrieving info from function
Message ID:
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

	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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About