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

📄 ch37_04.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 2 页
字号:
CLASS="literal">\b</CODE>'s or whatever.With Perl, it's all the same&nbsp;- and, as far as I can tell, a propersuperset of all the others.</P><PCLASS="para">Perl has a fully functional symbolic debugger (written, of course, inPerl) that is an indispensable aid in debugging complex programs.Neither the shell nor <EMCLASS="emphasis">sed</EM>/<EMCLASS="emphasis">awk</EM>/<EMCLASS="emphasis">sort</EM>/<EMCLASS="emphasis">tr</EM>/... havesuch a thing.</P><PCLASS="para">Perl has a loop control mechanism that's more powerful even than C's.You can do the equivalent of a <EMCLASS="emphasis">break</EM> or <EMCLASS="emphasis">continue</EM>(<EMCLASS="emphasis">last</EM> and <EMCLASS="emphasis">next</EM> in Perl) of any arbitrary loop, not merelythe nearest enclosing one.  You can even do a kind of <EMCLASS="emphasis">continue</EM>that doesn't trigger the re-initialization part of a loop, somethingyou may, from time to time, want to do.</P><PCLASS="para">Perl's data types and operators are richer than the shells' or<EMCLASS="emphasis">awk</EM>'s, because you have scalars, numerically-indexed arrays(lists), and string-indexed (hashed) arrays.  Each of these holdsarbitrary data values, including floating-point numbers, for whichmathematic built-in subroutines and power operators are available.  Itcan handle binary data of arbitrary size.</P><PCLASS="para">Speaking of LISP, you can generate strings, perhaps with<EMCLASS="emphasis">sprintf</EM>&nbsp;(&nbsp;), and then <EMCLASS="emphasis">eval</EM> them.  That way you cangenerate code on the fly.  You can even do lambda-type functions thatreturn newly created functions that you can call later. The scoping ofvariables is dynamic; fully recursive subroutines are supported; andyou can pass or return any type of data into or out of yoursubroutines.</P><PCLASS="para">You have a built-in automatic formatter for generating pretty printedforms with automatic pagination and headers and center-justified andtext-filled fields like <CODECLASS="literal">%(|fmt)s</CODE>, if you can imagine what thatwould actually be were it legal.</P><PCLASS="para">There's a mechanism for writing<SPANCLASS="link">SUID (<ACLASS="linkend"HREF="ch01_23.htm"TITLE="File Access Permissions ">1.23</A>)</SPAN>programs that can be made more secure than even C programs, thanks toan elaborate data-tracing mechanism that understands the &quot;taintedness&quot;of data derived from external sources.  It won't let you do anythingreally stupid that you might not have thought of.</P><PCLASS="para">You have access to just about any system-related function or systemcall, like <EMCLASS="emphasis">ioctl</EM>s, <EMCLASS="emphasis">fcntl</EM>, <EMCLASS="emphasis">select</EM>, <EMCLASS="emphasis">pipe</EM> and<EMCLASS="emphasis">fork</EM>, <EMCLASS="emphasis">getc</EM>, <EMCLASS="emphasis">socket</EM> and <EMCLASS="emphasis">bind</EM>, and <EMCLASS="emphasis">connect</EM>and <EMCLASS="emphasis">attach</EM>, and indirect <EMCLASS="emphasis">syscall</EM> invocation, as well asthings like <EMCLASS="emphasis">getpwuid</EM>, <EMCLASS="emphasis">gethostbyname</EM>, etc.  You canread in binary data laid out by a C program or system call usingstructure-conversion templates.</P><PCLASS="para">At the same time you can get at the high-level shell-type operationslike the<SPANCLASS="link"><EMCLASS="emphasis">-r</EM> or <EMCLASS="emphasis">-w</EM> tests (<ACLASS="linkend"HREF="ch44_20.htm"TITLE="test: Testing Files and Strings ">44.20</A>)</SPAN>on files or<SPANCLASS="link"><CODECLASS="literal">`backquote`</CODE> (<ACLASS="linkend"HREF="ch09_16.htm"TITLE="Command Substitution ">9.16</A>)</SPAN>command interpolation.  You can do file-globbing with the<SPANCLASS="link"><CODECLASS="literal">&lt;*.[</CODE><CODECLASS="replaceable"><I>ch</I></CODE><CODECLASS="literal">]&gt;</CODE> (<ACLASS="linkend"HREF="ch15_01.htm#UPT-ART-1480"TITLE="File Naming Wildcards ">15.1</A>)</SPAN>notation or do low-level <EMCLASS="emphasis">readdir</EM>s as suits your fancy.</P><PCLASS="para">DBM files can be accessed using simple array notation.  This is reallynice for dealing with system databases (aliases, news, ...), efficientaccess mechanisms over large data sets, and for keeping persistentdata.</P><PCLASS="para">Don't be dismayed by the apparent complexity of what I've justdiscussed.  Perl is actually very easy to learn because so much of itderives from existing tools.  It's like interpreter C with <EMCLASS="emphasis">sh</EM>,<EMCLASS="emphasis">sed</EM>, <EMCLASS="emphasis">awk</EM>, and a lot more built into it.  And, finally,there's a lot of code out there already written in Perl, includinglibraries to handle things you don't feel like re-implementing.<ACLASS="indexterm"NAME="AUTOID-42056"></A></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TC</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch37_03.htm"TITLE="37.3 Three Great Virtues of a Programmer "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 37.3 Three Great Virtues of a Programmer "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch37_05.htm"TITLE="37.5 And Now, Perl 5 "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 37.5 And Now, Perl 5 "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">37.3 Three Great Virtues of a Programmer </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">37.5 And Now, Perl 5 </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

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