📄 ch32_40.htm
字号:
<html><head><title>Sys::Hostname (Programming Perl)</title><!-- STYLESHEET --><link rel="stylesheet" type="text/css" href="../style/style1.css"><!-- METADATA --><!--Dublin Core Metadata--><meta name="DC.Creator" content=""><meta name="DC.Date" content=""><meta name="DC.Format" content="text/xml" scheme="MIME"><meta name="DC.Generator" content="XSLT stylesheet, xt by James Clark"><meta name="DC.Identifier" content=""><meta name="DC.Language" content="en-US"><meta name="DC.Publisher" content="O'Reilly & Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="Sys::Hostname"><meta name="DC.Type" content="Text.Monograph"></head><body><!-- START OF BODY --><!-- TOP BANNER --><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home"><map name="banner-map"><AREA SHAPE="RECT" COORDS="0,0,466,71" HREF="index.htm" ALT="Programming Perl"><AREA SHAPE="RECT" COORDS="467,0,514,18" HREF="jobjects/fsearch.htm" ALT="Search this book"></map><!-- TOP NAV BAR --><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch32_39.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch32_01.htm">Chapter 32: Standard Modules</a></td><td align="right" valign="top" width="172"><a href="ch32_41.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h2 class="sect1">32.40. Sys::Hostname</h2><p><blockquote><pre class="programlisting">use Sys::Hostname;$hostname = hostname();</pre></blockquote>The <tt class="literal">Sys::Hostname</tt> module supplies just one function, <tt class="literal">hostname</tt>,which makes up for that fact by busting its behind to try to figure outwhat your current host calls itself. On those systems that support thestandard <em class="emphasis">gethostname</em>(2) syscall, this is used, as it's the mostefficient method.<a href="#FOOTNOTE-6">[6]</a> On other systems, output from the standard<em class="emphasis">hostname</em>(1) is used. On still others, it calls the <em class="emphasis">uname</em>(3)function in your C library, which is also accessible as <tt class="literal">POSIX::uname</tt>from Perl. If these strategies all fail, more valiant attempts aremade. Whatever your native system thinks makes sense, Perl tries itsbest to go along with it. On some systems, this hostname may not befully qualified with the domain name; see the <tt class="literal">Net::Domain</tt> module from CPAN if you need that.</p><blockquote class="footnote"><a name="FOOTNOTE-6"></a><p>[6] Which is available directly as theunexported <tt class="literal">Sys::Hostname::ghname</tt> function, but don't tell anyone wetold you.</p></blockquote><p>Another consideration is that <tt class="literal">hostname</tt> returns just one value, butyour system could have multiple network interfaces configured, so youmight not get back the name associated with the interface you'reinterested in if you're planning on using this module for certain sorts ofsocket programming. There are cases where you'll probably have toscrounge around in the output from the <em class="emphasis">ifconfig</em>(8) command, or yoursystem's moral equivalent.</p><!-- BOTTOM NAV BAR --><hr width="515" align="left"><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch32_39.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0"></a></td><td align="right" valign="top" width="172"><a href="ch32_41.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">32.39. Symbol</td><td align="center" valign="top" width="171"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0"></a></td><td align="right" valign="top" width="172">32.41. Sys::Syslog</td></tr></table></div><hr width="515" align="left"><!-- LIBRARY NAV BAR --><img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p><font size="-1"><a href="copyrght.htm">Copyright © 2001</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"> <area shape="rect" coords="2,-1,79,99" href="../index.htm"><area shape="rect" coords="84,1,157,108" href="../perlnut/index.htm"><area shape="rect" coords="162,2,248,125" href="../prog/index.htm"><area shape="rect" coords="253,2,326,130" href="../advprog/index.htm"><area shape="rect" coords="332,1,407,112" href="../cookbook/index.htm"><area shape="rect" coords="414,2,523,103" href="../sysadmin/index.htm"></map><!-- END OF BODY --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -