perlfaq3.html
来自「perl教程」· HTML 代码 · 共 1,053 行 · 第 1/5 页
HTML
1,053 行
</pre>
<pre>
<span class="variable">@junk</span> <span class="operator">=</span> <span class="string">`cat /etc/motd`</span><span class="operator">;</span>
<span class="variable">$count</span> <span class="operator">=</span> <span class="number">10_000</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">timethese</span><span class="operator">(</span><span class="variable">$count</span><span class="operator">,</span> <span class="operator">{</span>
<span class="string">'map'</span> <span class="operator">=></span> <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span> <span class="keyword">my</span> <span class="variable">@a</span> <span class="operator">=</span> <span class="variable">@junk</span><span class="operator">;</span>
<span class="keyword">map</span> <span class="operator">{</span> <span class="regex">s/a/b/</span> <span class="operator">}</span> <span class="variable">@a</span><span class="operator">;</span>
<span class="keyword">return</span> <span class="variable">@a</span> <span class="operator">},</span>
<span class="string">'for'</span> <span class="operator">=></span> <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span> <span class="keyword">my</span> <span class="variable">@a</span> <span class="operator">=</span> <span class="variable">@junk</span><span class="operator">;</span>
<span class="keyword">for</span> <span class="operator">(</span><span class="variable">@a</span><span class="operator">)</span> <span class="operator">{</span> <span class="regex">s/a/b/</span> <span class="operator">};</span>
<span class="keyword">return</span> <span class="variable">@a</span> <span class="operator">},</span>
<span class="operator">}</span><span class="operator">);</span>
</pre>
<p>This is what it prints (on one machine--your results will be dependent
on your hardware, operating system, and the load on your machine):</p>
<pre>
Benchmark: timing 10000 iterations of for, map...
for: 4 secs ( 3.97 usr 0.01 sys = 3.98 cpu)
map: 6 secs ( 4.97 usr 0.00 sys = 4.97 cpu)</pre>
<p>Be aware that a good benchmark is very hard to write. It only tests the
data you give it and proves little about the differing complexities
of contrasting algorithms.</p>
<p>
</p>
<h2><a name="how_do_i_crossreference_my_perl_programs">How do I cross-reference my Perl programs?</a></h2>
<p>The B::Xref module can be used to generate cross-reference reports
for Perl programs.</p>
<pre>
perl -MO=Xref[,OPTIONS] scriptname.plx</pre>
<p>
</p>
<h2><a name="is_there_a_prettyprinter__formatter__for_perl">Is there a pretty-printer (formatter) for Perl?</a></h2>
<p>Perltidy is a Perl script which indents and reformats Perl scripts
to make them easier to read by trying to follow the rules of the
<a href="../../lib/Pod/perlstyle.html">the perlstyle manpage</a>. If you write Perl scripts, or spend much time reading
them, you will probably find it useful. It is available at
<a href="http://perltidy.sourceforge.net">http://perltidy.sourceforge.net</a></p>
<p>Of course, if you simply follow the guidelines in <a href="../../lib/Pod/perlstyle.html">the perlstyle manpage</a>,
you shouldn't need to reformat. The habit of formatting your code
as you write it will help prevent bugs. Your editor can and should
help you with this. The perl-mode or newer cperl-mode for emacs
can provide remarkable amounts of help with most (but not all)
code, and even less programmable editors can provide significant
assistance. Tom Christiansen and many other VI users swear by
the following settings in vi and its clones:</p>
<pre>
<span class="variable">set</span> <span class="variable">ai</span> <span class="variable">sw</span><span class="operator">=</span><span class="number">4</span>
<span class="keyword">map</span><span class="operator">!</span> <span class="operator">^</span><span class="variable">O</span> <span class="operator">{^</span><span class="variable">M</span><span class="operator">}^</span><span class="operator">[</span><span class="variable">O</span><span class="operator">^</span><span class="variable">T</span>
</pre>
<p>Put that in your <em>.exrc</em> file (replacing the caret characters
with control characters) and away you go. In insert mode, ^T is
for indenting, ^D is for undenting, and ^O is for blockdenting--
as it were. A more complete example, with comments, can be found at
<a href="http://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gz">http://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gz</a></p>
<p>The a2ps <a href="http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz">http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz</a> does
lots of things related to generating nicely printed output of
documents, as does enscript at <a href="http://people.ssh.fi/mtr/genscript/">http://people.ssh.fi/mtr/genscript/</a> .</p>
<p>
</p>
<h2><a name="is_there_a_ctags_for_perl">Is there a ctags for Perl?</a></h2>
<p>(contributed by brian d foy)</p>
<p>Exuberent ctags supports Perl: <a href="http://ctags.sourceforge.net/">http://ctags.sourceforge.net/</a></p>
<p>You might also try pltags: <a href="http://www.mscha.com/pltags.zip">http://www.mscha.com/pltags.zip</a></p>
<p>
</p>
<h2><a name="is_there_an_ide_or_windows_perl_editor">Is there an IDE or Windows Perl Editor?</a></h2>
<p>Perl programs are just plain text, so any editor will do.</p>
<p>If you're on Unix, you already have an IDE--Unix itself. The UNIX
philosophy is the philosophy of several small tools that each do one
thing and do it well. It's like a carpenter's toolbox.</p>
<p>If you want an IDE, check the following (in alphabetical order, not
order of preference):</p>
<dl>
<dt><strong><a name="item_eclipse">Eclipse</a></strong>
<dd>
<p><a href="http://e-p-i-c.sf.net/">http://e-p-i-c.sf.net/</a></p>
</dd>
<dd>
<p>The Eclipse Perl Integration Project integrates Perl
editing/debugging with Eclipse.</p>
</dd>
</li>
<dt><strong><a name="item_enginsite">Enginsite</a></strong>
<dd>
<p><a href="http://www.enginsite.com/">http://www.enginsite.com/</a></p>
</dd>
<dd>
<p>Perl Editor by EngInSite is a complete integrated development
environment (IDE) for creating, testing, and debugging Perl scripts;
the tool runs on Windows 9x/NT/2000/XP or later.</p>
</dd>
</li>
<dt><strong><a name="item_komodo">Komodo</a></strong>
<dd>
<p><a href="http://www.ActiveState.com/Products/Komodo/">http://www.ActiveState.com/Products/Komodo/</a></p>
</dd>
<dd>
<p>ActiveState's cross-platform (as of October 2004, that's Windows, Linux,
and Solaris), multi-language IDE has Perl support, including a regular expression
debugger and remote debugging.</p>
</dd>
</li>
<dt><strong><a name="item_open_perl_ide">Open Perl IDE</a></strong>
<dd>
<p><a href="http://open-perl-ide.sourceforge.net/">http://open-perl-ide.sourceforge.net/</a></p>
</dd>
<dd>
<p>Open Perl IDE is an integrated development environment for writing
and debugging Perl scripts with ActiveState's ActivePerl distribution
under Windows 95/98/NT/2000.</p>
</dd>
</li>
<dt><strong><a name="item_optiperl">OptiPerl</a></strong>
<dd>
<p><a href="http://www.optiperl.com/">http://www.optiperl.com/</a></p>
</dd>
<dd>
<p>OptiPerl is a Windows IDE with simulated CGI environment, including
debugger and syntax highlighting editor.</p>
</dd>
</li>
<dt><strong><a name="item_perlbuilder">PerlBuilder</a></strong>
<dd>
<p><a href="http://www.solutionsoft.com/perl.htm">http://www.solutionsoft.com/perl.htm</a></p>
</dd>
<dd>
<p>PerlBuidler is an integrated development environment for Windows that
supports Perl development.</p>
</dd>
</li>
<dt><strong><a name="item_visiperl_2b">visiPerl+</a></strong>
<dd>
<p><a href="http://helpconsulting.net/visiperl/">http://helpconsulting.net/visiperl/</a></p>
</dd>
<dd>
<p>From Help Consulting, for Windows.</p>
</dd>
</li>
<dt><strong><a name="item_visual_perl">Visual Perl</a></strong>
<dd>
<p><a href="http://www.activestate.com/Products/Visual_Perl/">http://www.activestate.com/Products/Visual_Perl/</a></p>
</dd>
<dd>
<p>Visual Perl is a Visual Studio.NET plug-in from ActiveState.</p>
</dd>
</li>
<dt><strong><a name="item_zeus">Zeus</a></strong>
<dd>
<p><a href="http://www.zeusedit.com/lookmain.html">http://www.zeusedit.com/lookmain.html</a></p>
</dd>
<dd>
<p>Zeus for Window is another Win32 multi-language editor/IDE
that comes with support for Perl:</p>
</dd>
</li>
</dl>
<p>For editors: if you're on Unix you probably have vi or a vi clone
already, and possibly an emacs too, so you may not need to download
anything. In any emacs the cperl-mode (M-x cperl-mode) gives you
perhaps the best available Perl editing mode in any editor.</p>
<p>If you are using Windows, you can use any editor that lets you work
with plain text, such as NotePad or WordPad. Word processors, such as
Microsoft Word or WordPerfect, typically do not work since they insert
all sorts of behind-the-scenes information, although some allow you to
save files as "Text Only". You can also download text editors designed
specifically for programming, such as Textpad (
<a href="http://www.textpad.com/">http://www.textpad.com/</a> ) and UltraEdit ( <a href="http://www.ultraedit.com/">http://www.ultraedit.com/</a> ),
among others.</p>
<p>If you are using MacOS, the same concerns apply. MacPerl (for Classic
environments) comes with a simple editor. Popular external editors are
BBEdit ( <a href="http://www.bbedit.com/">http://www.bbedit.com/</a> ) or Alpha (
<a href="http://www.his.com/~jguyer/Alpha/Alpha8.html">http://www.his.com/~jguyer/Alpha/Alpha8.html</a> ). MacOS X users can use
Unix editors as well. Neil Bowers (the man behind Geekcruises) has a
list of Mac editors that can handle Perl (
<a href="http://www.neilbowers.org/macperleditors.html">http://www.neilbowers.org/macperleditors.html</a> ).</p>
<dl>
<dt><strong><a name="item_gnu_emacs">GNU Emacs</a></strong>
<dd>
<p><a href="http://www.gnu.org/software/emacs/windows/ntemacs.html">http://www.gnu.org/software/emacs/windows/ntemacs.html</a></p>
</dd>
</li>
<dt><strong><a name="item_microemacs">MicroEMACS</a></strong>
<dd>
<p><a href="http://www.microemacs.de/">http://www.microemacs.de/</a></p>
</dd>
</li>
<dt><strong><a name="item_xemacs">XEmacs</a></strong>
<dd>
<p><a href="http://www.xemacs.org/Download/index.html">http://www.xemacs.org/Download/index.html</a></p>
</dd>
</li>
<dt><strong><a name="item_jed">Jed</a></strong>
<dd>
<p><a href="http://space.mit.edu/~davis/jed/">http://space.mit.edu/~davis/jed/</a></p>
</dd>
</li>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?