home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / perl / hostname.pl < prev    next >
Perl Script  |  1992-03-10  |  475b  |  23 lines

  1. #
  2. # file: hostname.pl
  3. # usage: $hostname = &'hostname;
  4. #
  5. # purpose: get hostname -- try method until we get an answer 
  6. #    or return "Amnesiac!"
  7. #
  8.  
  9. package hostname;
  10.  
  11. sub main'hostname {
  12.     if (!defined $hostname) {
  13.     $hostname =  ( -x '/bin/hostname'   && `/bin/hostname` ) 
  14.           || ( -x '/bin/uname'      && `/bin/uname -n` )
  15.           || ( -x '/usr/bin/uuname' && `/usr/bin/uuname -l`)
  16.           || 'Amnesiac! ';  # trailing space is for chop
  17.     chop $hostname;
  18.     }
  19.     $hostname;
  20. }
  21.  
  22. 1;
  23.