in reply to not getting hostname correctly on UNIX

system doesn't do what you want. You should be using backticks:

$hostname = `/bin/hostname`;

Also, you're needlessly using a global for a return value:

sub getHostname { return `/bin/hostname`; } my $hostname = getHostname; print "hostname: $hostname\n";

Replies are listed 'Best First'.
Re^2: not getting hostname correctly on UNIX
by blazar (Canon) on Dec 23, 2005 at 11:36 UTC

    Very valuable advice that the OP would better take into account. But since nobody has mentioned it yet, and he wrote so many lines of code for this simple task, it is also worth pointing out that he may well save himself all this trouble and use Sys::Hostname instead, which I've always found to be quite reliable.