On Wed, 3 Oct 2007, Chris Lewis wrote:
Robin Bowes wrote:
John Peacock wrote:
I'm sure that there is a platform-independent way to get the hostname
How about:
use Sys::Hostname;
$host = hostname;
Returns the non-qualified hostname (at least on this Solaris). I guess when
it boils down to it, this machine is misconfigured. Sigh.
I'm pretty sure that returning just the hostname without the domain name
is not a misconfiguration, although it is a bit annoying.
I've written code to get the fqdn from just the hostname that works
provided is working in a sane way:
sub fqdn {
my $local = hostname();
return $local unless _is_short($local);
return ( gethostbyname($local) )[0] || $local;
}
sub _is_short {
return 0 if $_[0] =~ /\./;
return 1;
}
I don't know if this is more or less portable than just calling "hostname
--fqdn", but it works on Linux (heh ;)
-dave
/*===================================================
VegGuide.Org www.BookIRead.com
Your guide to all that's veg. My book blog
===================================================*/