This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mktables: Move code
[perl5.git] / lib / hostname.pl
1 warn "Legacy library @{[(caller(0))[6]]} will be removed from the Perl core distribution in the next major release. Please install it from the CPAN distribution Perl4::CoreLibs. It is being used at @{[(caller)[1]]}, line @{[(caller)[2]]}.\n";
2
3 # From: asherman@fmrco.com (Aaron Sherman)
4 #
5 # This library is no longer being maintained, and is included for backward
6 # compatibility with Perl 4 programs which may require it.
7 # This legacy library is deprecated and will be removed in a future
8 # release of perl.
9 #
10 # In particular, this should not be used as an example of modern Perl
11 # programming techniques.
12 #
13 # Suggested alternative: Sys::Hostname
14
15 sub hostname
16 {
17         local(*P,@tmp,$hostname,$_);
18         if (open(P,"hostname 2>&1 |") && (@tmp = <P>) && close(P))
19         {
20                 chop($hostname = $tmp[$#tmp]);
21         }
22         elsif (open(P,"uname -n 2>&1 |") && (@tmp = <P>) && close(P))
23         {
24                 chop($hostname = $tmp[$#tmp]);
25         }
26         else
27         {
28                 die "$0: Cannot get hostname from 'hostname' or 'uname -n'\n";
29         }
30         @tmp = ();
31         close P; # Just in case we failed in an odd spot....
32         $hostname;
33 }
34
35 1;