⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch14_03.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
字号:
<html><head><title>The Environment Variables (Learning Perl, 3rd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Randal L. Schwartz and Tom Phoenix" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596001320L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Learning Perl, 3rd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Learning Perl, 3rd Edition" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch14_02.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"></a></td><td align="right" valign="top" width="228"><a href="ch14_04.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">14.3. The Environment Variables</h2><p>When you're starting another process (with any of the methodsdiscussed here), you may need to set up its<a name="INDEX-961" /><a name="INDEX-962" />environmentin one way or another. As we mentioned earlier, you could start theprocess with a certain working directory, which it inherits from yourprocess. Another common configuration detail is the environmentvariables.</p><p>The best-known environment variable is<tt class="literal">PATH</tt><a name="INDEX-963" />. (If you've never heard of it,you probably haven't used a system that has environmentvariables.) On Unix and similar systems, <tt class="literal">PATH</tt> is acolon-separated list of directories that may hold programs. When youtype a command like <i class="command">rm fred</i>, the system will lookfor the <em class="emphasis">rm</em> command in that list of directories,in order. Perl (or your system) will use <tt class="literal">PATH</tt>whenever it needs to find the program to run. If the program in turnruns other programs, those may also be found along the<tt class="literal">PATH</tt>. (Of course, if you give a complete name fora command, such as <em class="emphasis">/bin/echo</em>, there's noneed to search <tt class="literal">PATH</tt>. But that's generallymuch less convenient.)</p><p>In Perl, the environment variables are available via the special<tt class="literal">%ENV</tt><a name="INDEX-964" /> hash; each key in this hash represents oneenvironment variable. At the start of your program's execution,<tt class="literal">%ENV</tt> holds values it has inherited from its parentprocess (generally the shell). Modifying this hash changes theenvironment variables, which will then be inherited by new processesand possibly used by Perl as well. For example, suppose you wished torun the system's <tt class="literal">make</tt> utility (whichtypically runs other programs), and you want to use a privatedirectory as the first place to look for commands (including<tt class="literal">make</tt> itself). And let's say that youdon't want the <tt class="literal">IFS</tt> environment variable tobe set when you run the command, because that might cause<i class="command">make</i> or some subcommand do the wrong thing. Herewe go:</p><blockquote><pre class="code">$ENV{'PATH'} = "/home/rootbeer/bin:$ENV{'PATH'}";delete $ENV{'IFS'};my $make_result = system "make";</pre></blockquote><p>Newly created processes will generally inherit from their parent theenvironment variables, the current working directory, the standardinput, output, and error streams, and a few more-esoteric items. Seethe documentation about programming on your system for more details.(But your program can't change the environment for the shell orother parent process that started it, on most systems.)</p><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch14_02.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img alt="Home" border="0" src="../gifs/txthome.gif" /></a></td><td align="right" valign="top" width="228"><a href="ch14_04.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">14.2. The exec Function</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img alt="Book Index" border="0" src="../gifs/index.gif" /></a></td><td align="right" valign="top" width="228">14.4. Using Backquotes to Capture Output</td></tr></table></div><hr width="684" align="left" /><img alt="Library Navigation Links" border="0" src="../gifs/navbar.gif" usemap="#library-map" /><p><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -