Red_Dragon has asked for the wisdom of the Perl Monks concerning the following question:

Greetings and salutations, most sagacious Monks,

I am still on a Perl quest, which begs today's question:

Is there some way that I can retrieve the name of the box that my Perl script is running on. This may be a simple thing for someone that has done it before, I however have not and need your help. Thanks for any time you can invest in me.

R_D

20040928 Edit by Steve_p: Changed title from 'What's in a Name?'

Replies are listed 'Best First'.
Re: Finding a machine's name?
by Happy-the-monk (Canon) on Sep 28, 2004 at 14:29 UTC
      Thank you for your prompt response.
Re: Finding a machine's name?
by Zaxo (Archbishop) on Sep 28, 2004 at 14:26 UTC

    One way, my $hostname = `/bin/hostname`; Given that, you can call gethostbyname to get more information.

    If you're in a shell environment, you're likely to have the purely perlish,

    my ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname $ENV{'HOSTNAME'};
    That will probably be available in the cgi environment, too, but probably not in cron.

    After Compline,
    Zaxo

      This method also works in Windows by skipping the /bin/
      my $host = `hostname`;
      Many thanks for the thorough example
Re: Finding a machine's name?
by diotalevi (Canon) on Sep 28, 2004 at 14:24 UTC
    The method depends on the operating system. See what the hostname or net name commands do for you.
Re: Finding a machine's name?
by ikegami (Patriarch) on Sep 28, 2004 at 15:48 UTC
    There's also $ENV{'COMPUTERNAME'} in Windows.