ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/staticperl/perl/lib/hostname.pl
Revision: 1.1
Committed: Thu Jun 30 14:27:09 2005 UTC (21 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: PERL-5-8-7, HEAD
Branch point for: PERL
Log Message:
*** empty log message ***

File Contents

# Content
1 # From: asherman@fmrco.com (Aaron Sherman)
2 #
3 # This library is no longer being maintained, and is included for backward
4 # compatibility with Perl 4 programs which may require it.
5 #
6 # In particular, this should not be used as an example of modern Perl
7 # programming techniques.
8 #
9 # Suggested alternative: Sys::Hostname
10 #
11 sub hostname
12 {
13 local(*P,@tmp,$hostname,$_);
14 if (open(P,"hostname 2>&1 |") && (@tmp = <P>) && close(P))
15 {
16 chop($hostname = $tmp[$#tmp]);
17 }
18 elsif (open(P,"uname -n 2>&1 |") && (@tmp = <P>) && close(P))
19 {
20 chop($hostname = $tmp[$#tmp]);
21 }
22 else
23 {
24 die "$0: Cannot get hostname from 'hostname' or 'uname -n'\n";
25 }
26 @tmp = ();
27 close P; # Just in case we failed in an odd spot....
28 $hostname;
29 }
30
31 1;