This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make pp_reverse fetch the lexical $_ from the correct pad
[perl5.git] / lib / hostname.pl
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 # This legacy library is deprecated and will be removed in a future
6 # release of perl.
7 #
8 # In particular, this should not be used as an example of modern Perl
9 # programming techniques.
10 #
11 # Suggested alternative: Sys::Hostname
12
13 sub hostname
14 {
15         local(*P,@tmp,$hostname,$_);
16         if (open(P,"hostname 2>&1 |") && (@tmp = <P>) && close(P))
17         {
18                 chop($hostname = $tmp[$#tmp]);
19         }
20         elsif (open(P,"uname -n 2>&1 |") && (@tmp = <P>) && close(P))
21         {
22                 chop($hostname = $tmp[$#tmp]);
23         }
24         else
25         {
26                 die "$0: Cannot get hostname from 'hostname' or 'uname -n'\n";
27         }
28         @tmp = ();
29         close P; # Just in case we failed in an odd spot....
30         $hostname;
31 }
32
33 1;