Provided by: manpages-zh_1.5-1_all bug

NAME

       perlfaq3 - 編程工具 (2003/11/24 19:55:50)

DESCRIPTIONyz
       編程工具和編程支持

      p@ ()?

       你到 CPAN(見 perlfaq2)找過了嗎?也許別人已經寫了某-
       蚍珩掍i以解決你的問題。你查過相關的說明檔案了嗎 (man
       pages)?以下是一份概n的索引:

               基礎Basics          perldata, perlvar, perlsyn, perlop, perlsub
               執行Execution       perlrun, perldebug
               函數Functions       perlfunc
               對象Objects         perlref, perlmod, perlobj, perltie
               數據結構Data Structures perlref, perllol, perldsc
               模塊Modules         perlmod, perlmodlib, perlsub
               正則表達式Regexes         perlre, perlfunc, perlop, perllocale
               移植Moving to perl5 perltrap, perl
               連接Linking w/C     perlxstut, perlxs, perlcall, perlguts, perlembed
               其他Various         http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz
                               (這不是一茪漭U間A但是仍然很有用
                                是有關 Perl 技術的大量技巧)

       perltoc裏有一份粗略的 perl 說明檔案組的目錄

      pH Perl?

       典型的作法是使用 perldebug(1)說明檔案裏提到的 Perl 除蟲器,在一-
       荂u空的」(譯者:即不存在的)程式上執行,像這樣:

           perl -de 42

       接下來所打入的任意合法 Perl程式碼皆會立刻被p算。同時,你可以檢查符號表
       (symbol table)、取得堆疊的記錄 (stack backtraces)、檢視變數-
       B設定阻斷點 (set breakpoints) 以及其他符號式除蟲器 (symbolic
       debuggers) 所能作的動作。

       Perl shell?

       The psh (Perl sh) is currently at version 1.8. The Perl Shell is a
       shell that combines the interactive nature of a Unix shell with the
       power of Perl. The goal is a full featured shell that behaves as
       expected for normal shell activity and uses Perl syntax and
       functionality for control-flow statements and other things.  You can
       get psh at http://www.focusresearch.com/gregor/psh/ .

       Zoidberg is a similar project and provides a shell written in perl,
       configured in perl and operated in perl. It is intended as a login
       shell and development environment. It can be found at
       http://zoidberg.sf.net/ or your local CPAN mirror.

       The Shell.pm module (distributed with Perl) makes Perl try commands
       which aren't part of the Perl language as shell commands.  perlsh from
       the source distribution is simplistic and uninteresting, but may still
       be what you want.

      dtwFH

       You can use the ExtUtils::Installed module to show all installed
       distributions, although it can take awhile to do its magic.  The
       standard library which comes with Perl just shows up as "Perl"
       (although you can get those with Module::CoreList).

               use ExtUtils::Installed;

               my $inst    = ExtUtils::Installed->new();
               my @modules = $inst->modules();

       If you want a list of all of the Perl module filenames, you can use
       File::Find::Rule.

               use File::Find::Rule;

               my @files = File::Find::Rule->file()->name( '*.pm' )->in( @INC );

       If you do not have that module, you can do the same thing with
       File::Find which is part of the standard library.

           use File::Find;
           my @files;

           find sub { push @files, $File::Find::name if -f _ && /\.pm$/ },
                @INC;

               print join "\n", @files;

       If you simply need to quickly check to see if a module is available,
       you can check for its documentation.  If you can read the documentation
       the module is most likely installed.  If you cannot read the
       documentation, the module might not have any (in rare cases).

               prompt% perldoc Module::Name

       You can also try to include the module in a one-liner to see if perl
       finds it.

               perl -MModule::Name -e1

      p Perl{?

       你用過 "use warnings" 或 "-w" 嗎?它戔狴恅筆i模式,來檢測不確定的代碼。

       你用過 "use strict" 嗎?It prevents you from using symbolic references,
       makes you predeclare any subroutines that you call as bare words, and
       (probably most importantly) forces you to predeclare your variables
       with "my", "our", or "use vars".

       Did you check the return values of each and every system call?  The
       operating system (and thus Perl) tells you whether they worked, and if
       not why.

         open(FH, "> /etc/cantwrite")
           or die "Couldn't write to /etc/cantwrite: $!\n";

       Did you read perltrap?  It's full of gotchas for old and new Perl
       programmers and even has sections for those of you who are upgrading
       from languages like awk and C.

       Have you tried the Perl debugger, described in perldebug?  You can step
       through your program and see what it's doing and thus work out why what
       it's doing isn't what it should be doing.

      p (profile) perl{?

       你該自 CPAN抓取 Devel::DProf 模組,並且使用 perl 標準套件所附的
       Benchmark.pm。 Benchmark.pm讓你測量程式碼的某部份在執行上所花的時間,而
       Devel::DProf則詳細地替你分析一部份的程式用掉多少時間。

       Here's a sample use of Benchmark:

         use Benchmark;

         @junk = `cat /etc/motd`;
         $count = 10_000;

         timethese($count, {
                   'map' => sub { my @a = @junk;
                                  map { s/a/b/ } @a;
                                  return @a },
                   'for' => sub { my @a = @junk;
                                  for (@a) { s/a/b/ };
                                  return @a },
                  });

       This is what it prints (on one machine--your results will be dependent
       on your hardware, operating system, and the load on your machine):

         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)

       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 PerlPerl?

       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
       perlstyle. If you write Perl scripts, or spend much time reading them,
       you will probably find it useful.  It is available at
       http://perltidy.sourceforge.net

       Of course, if you simply follow the guidelines in perlstyle, 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:

           set ai sw=4
           map! ^O {^M}^[O^T

       Put that in your .exrc 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
       http://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gz

       The a2ps http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz does
       lots of things related to generating nicely printed output of
       documents, as does enscript at http://people.ssh.fi/mtr/genscript/ .

       Perlctags?

       Recent versions of ctags do much more than older versions did.
       EXUBERANT CTAGS is available from http://ctags.sourceforge.net/ and
       does a good job of making tags files for perl code.

       There is also a simple one at
       http://www.cpan.org/authors/id/TOMC/scripts/ptags.gz which may do the
       trick.  It can be easy to hack this into what you want.

       Is there an IDE or Windows Perl Editor?

       Perl programs are just plain text, so any editor will do.

       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.

       If you want an IDE, check the following:

       Komodo
           ActiveState's cross-platform (as of April 2001 Windows and Linux),
           multi-language IDE has Perl support, including a regular expression
           debugger and remote debugging (
           http://www.ActiveState.com/Products/Komodo/index.html ).  (Visual
           Perl, a Visual Studio.NET plug-in is currently (early 2001) in beta
           ( http://www.ActiveState.com/Products/VisualPerl/index.html )).

       The Object System
           ( http://www.castlelink.co.uk/object_system/ ) is a Perl web
           applications development IDE, apparently for any platform that runs
           Perl.

       Open Perl IDE
           ( http://open-perl-ide.sourceforge.net/ ) 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.

       PerlBuilder
           ( http://www.solutionsoft.com/perl.htm ) is an integrated
           development environment for Windows that supports Perl development.

       visiPerl+
           ( http://helpconsulting.net/visiperl/ ) From Help Consulting, for
           Windows.

       OptiPerl
           ( http://www.optiperl.com/ ) is a Windows IDE with simulated CGI
           environment, including debugger and syntax highlighting editor.

       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.

       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 ( http://www.textpad.com/
       ) and UltraEdit ( http://www.ultraedit.com/ ), among others.

       If you are using MacOS, the same concerns apply.  MacPerl (for Classic
       environments) comes with a simple editor.  Popular external editors are
       BBEdit ( http://www.bbedit.com/ ) or Alpha (
       http://www.kelehers.org/alpha/ ). MacOS X users can use Unix editors as
       well.

       GNU Emacs
           http://www.gnu.org/software/emacs/windows/ntemacs.html

       MicroEMACS
           http://www.microemacs.de/

       XEmacs
           http://www.xemacs.org/Download/index.html

       Jed http://space.mit.edu/~davis/jed/

       or a vi clone such as

       Elvis
           ftp://ftp.cs.pdx.edu/pub/elvis/ http://www.fh-wedel.de/elvis/

       Vile
           http://dickey.his.com/vile/vile.html

       Vim http://www.vim.org/

       For vi lovers in general, Windows or elsewhere:

               http://www.thomer.com/thomer/vi/vi.html

       nvi ( http://www.bostic.com/vi/ , available from CPAN in src/misc/) is
       yet another vi clone, unfortunately not available for Windows, but in
       UNIX platforms you might be interested in trying it out, firstly
       because strictly speaking it is not a vi clone, it is the real vi, or
       the new incarnation of it, and secondly because you can embed Perl
       inside it to use Perl as the scripting language.  nvi is not alone in
       this, though: at least also vim and vile offer an embedded Perl.

       The following are Win32 multilanguage editor/IDESs that support Perl:

       Codewright
           http://www.starbase.com/

       MultiEdit
           http://www.MultiEdit.com/

       SlickEdit
           http://www.slickedit.com/

       There is also a toyedit Text widget based editor written in Perl that
       is distributed with the Tk module on CPAN.  The ptkdb (
       http://world.std.com/~aep/ptkdb/ ) is a Perl/tk based debugger that
       acts as a development environment of sorts.  Perl Composer (
       http://perlcomposer.sourceforge.net/ ) is an IDE for Perl/Tk GUI
       creation.

       In addition to an editor/IDE you might be interested in a more powerful
       shell environment for Win32.  Your options include

       Bash
           from the Cygwin package ( http://sources.redhat.com/cygwin/ )

       Ksh from the MKS Toolkit ( http://www.mks.com/ ), or the Bourne shell
           of the U/WIN environment (
           http://www.research.att.com/sw/tools/uwin/ )

       Tcsh
           ftp://ftp.astron.com/pub/tcsh/ , see also
           http://www.primate.wisc.edu/software/csh-tcsh-book/

       Zsh ftp://ftp.blarg.net/users/amol/zsh/ , see also http://www.zsh.org/

       MKS and U/WIN are commercial (U/WIN is free for educational and
       research purposes), Cygwin is covered by the GNU Public License (but
       that shouldn't matter for Perl use).  The Cygwin, MKS, and U/WIN all
       contain (in addition to the shells) a comprehensive set of standard
       UNIX toolkit utilities.

       If you're transferring text files between Unix and Windows using FTP be
       sure to transfer them in ASCII mode so the ends of lines are
       appropriately converted.

       On Mac OS the MacPerl Application comes with a simple 32k text editor
       that behaves like a rudimentary IDE.  In contrast to the MacPerl
       Application the MPW Perl tool can make use of the MPW Shell itself as
       an editor (with no 32k limit).

       BBEdit and BBEdit Lite
           are text editors for Mac OS that have a Perl sensitivity mode (
           http://web.barebones.com/ ).

       Alpha
           is an editor, written and extensible in Tcl, that nonetheless has
           built in support for several popular markup and programming
           languages including Perl and HTML ( http://alpha.olm.net/ ).

       Pepper and Pe are programming language sensitive text editors for Mac
       OS X and BeOS respectively ( http://www.hekkelman.com/ ).

       vi PerlH

       For a complete version of Tom Christiansen's vi configuration file, see
       http://www.cpan.org/authors/Tom_Christiansen/scripts/toms.exrc.gz , the
       standard benchmark file for vi emulators.  The file runs best with nvi,
       the current version of vi out of Berkeley, which incidentally can be
       built with an embedded Perl interpreter--see
       http://www.cpan.org/src/misc/ .

       emacsperln?

       從大約 Emacs 19.22版 (version 19 patchlevel 22)起,已內含了 perl-
       mode.el及 perl 除蟲器的支援。它抸雩虓|和標準的 Emacs 19版一起出貨。

       在 perl鴝l碼的目錄下,你會找到一茈s作 ``emacs'' 的目錄,裏悼]括一
       cperl-mode
       可以把程式中的關鍵字上色、提供內文相關的協助以及其它方便的功能。

       注意:``main'foo''(其中的單引號)會讓 emacs的 perl-mode
       出問題,並且會弄亂內 縮 (indentation) 與高亮
       (hilighting)。不過你本來就該用 ``main::foo''的 (譯者按: main'foo
       是表示模組或 package的舊式寫法;新式的 [perl5的]寫法是 main::foo)。

      pb Perlcurses?

       The Curses module from CPAN provides a dynamically loadable object
       module interface to a curses library.  A small demo can be found at the
       directory http://www.cpan.org/authors/Tom_Christiansen/scripts/rep.gz ;
       this program repeats a command and updates the screen as needed,
       rendering rep ps axu similar to top.

       XTkPerl?

       Tk 模塊是一荍馴以 Perl 為基礎,惘V對象的接口,讓你不用學 Tcl也可以使用
       Tk工具組。Sx則是 Athena Widget set專用的介情C兩者都可在
       CPAN取得。參見分類
       http://www.cpan.org/modules/by-category/08_User_Interfaces/

       Invaluable for Perl/Tk programming are the Perl/Tk FAQ at
       http://w4.lns.cornell.edu/%7Epvhp/ptk/ptkTOC.html , the Perl/Tk
       Reference Guide available at
       http://www.cpan.org/authors/Stephen_O_Lidie/ , and the online manpages
       at http://www-users.cs.umn.edu/%7Eamundson/perl/perltk/toc.html .

      pa CGITkU@X]^?

       http://www.cpan.org/authors/id/SKUNZ/perlmenu.v4.0.tar.gz 是茈H
       curses為基礎的模組,可以達成你的n求。

      p Perl?

       最好是能設p一虒好的演算法
       (algorithm),這通常會讓程式有大不相同的表現。Jon Bentley's book
       Programming Pearls (沒有拼寫錯誤!) 中有些你或許想知道的增進效率小技巧。
       Advice on benchmarking boils down to: benchmark and profile to make
       sure you're optimizing the right part, look for better algorithms
       instead of microtuning your code, and when all else fails consider just
       buying faster hardware.  You will probably want to read the answer to
       the earlier question ``How do I profile my Perl programs?'' if you
       haven't done so already.

       其它方法包括自動載入較少使用的 Perl 程式碼。請參看標準 perl 套件中的
       AutoSplit及
       AutoLoader模組的用法。或當你能斷定程式執行效率的瓶頸在何處時,用
       C來寫那茬‘驉A就像用組合語言來撰寫
       C程式的瓶頸部份一樣。與此法相近的是使用以 C撰寫瓶 頸部份的模組 (例如
       CPAN中的 PDL 模組)。

       如果你目前是將你的 perl直譯器動態連結到 libc.so的話,-
       奐s作一份靜態連結到 libc.a的 perl直譯器可以提高
       10-25%的執行效能。雖然這會使你的 perl直譯器變得更D,但你的 Perl程式
       (及程式設p者) 或許會因此而感謝你。詳情請參考 perl標準套件鴝l碼版本中的
       INSTALL 檔案。

       使用
       undump程式把編譯後的檔案格式存到硬碟裏以加快執行的速度已經是老掉牙的手法了。它已不再是-
       茈i行的方法,因為這方法只有幾種孕x能用,況且它終究不是茠v本之 道。

      p Perl{@OH

       當問題變成時間與空間的交易時, Perl 幾乎總是用記憶體來幫忙解決問題。
       Perl中的純量 (Scalar) 耗掉的記憶體比 C中的字串形態還多,陣列又更多,
       更別談雜湊陣列了 (Hashes)。關於這一點,我-
       抪穔M還有很多工作得作,近來發佈的版本,已開始針對這些問題做改進了。例如,
       5.004 版中, 契_的散列鍵 (duplicate hash keys)
       由使用它的雜湊陣列共用,這樣就不用再奐s定份位置給它了。

       在某些情況下,使用 substr()或 vec()來模擬數組有很大的好處。例如,一-
       茼酗W千 茈洩L代數滌}列將佔用至少
       20,000位元組的空間,但是它可以被轉變為一 125位元組的位元向量 (bit
       vector)以節省相當可觀的記憶體。標準套件中的
       Tie::SubstrHash模組也能夠幫助特定形態的資料結構節省些記憶體。-
       Y你正在和一些特殊的資料結構奮戰 (例如,矩陣),用
       C寫的模組所耗掉的記憶體可能低於同功能並用 Perl寫的模組。

       另一件o一試的是,查一下你的 Perl是以系統內的 malloc 還是 Perl內含的
       malloc 編譯起來的。不論是荂A試著換成另一-
       荂A再看看這是否造成任何差別。關於 malloc的資訊可在 perl標準套件-
       鴝l碼版中的 INSTALL 檔案找到。鍵入 "perl -V:usemymalloc".
       就可以知道你是否在使用 perl的 malloc。

       Of course, the best way to save memory is to not do anything to waste
       it in the first place. Good programming practices can go a long way
       toward this:

       * Don't slurp!
           Don't read an entire file into memory if you can process it line by
           line. Or more concretely, use a loop like this:

                   #
                   # Good Idea
                   #
                   while (<FILE>) {
                      # ...
                   }

           instead of this:

                   #
                   # Bad Idea
                   #
                   @data = <FILE>;
                   foreach (@data) {
                       # ...
                   }

           When the files you're processing are small, it doesn't much matter
           which way you do it, but it makes a huge difference when they start
           getting larger.

       * Use map and grep selectively
           Remember that both map and grep expect a LIST argument, so doing
           this:

                   @wanted = grep {/pattern/} <FILE>;

           will cause the entire file to be slurped. For large files, it's
           better to loop:

                   while (<FILE>) {
                           push(@wanted, $_) if /pattern/;
                   }

       * Avoid unnecessary quotes and stringification
           Don't quote large strings unless absolutely necessary:

                   my $copy = "$large_string";

           makes 2 copies of $large_string (one for $copy and another for the
           quotes), whereas

                   my $copy = $large_string;

           only makes one copy.

           Ditto for stringifying large arrays:

                   {
                           local $, = "\n";
                           print @big_array;
                   }

           is much more memory-efficient than either

                   print join "\n", @big_array;

           or

                   {
                           local $" = "\n";
                           print "@big_array";
                   }

       * Pass by reference
           Pass arrays and hashes by reference, not by value. For one thing,
           it's the only way to pass multiple lists or hashes (or both) in a
           single call/return. It also avoids creating a copy of all the
           contents. This requires some judgment, however, because any changes
           will be propagated back to the original data. If you really want to
           mangle (er, modify) a copy, you'll have to sacrifice the memory
           needed to make one.

       * Tie large variables to disk.
           For "big" data stores (i.e. ones that exceed available memory)
           consider using one of the DB modules to store it on disk instead of
           in RAM. This will incur a penalty in access time, but that's
           probably better than causing your hard disk to thrash due to
           massive swapping.

      q^Owk?

       這樣是安全的,Perl的資源回收 (garbage collection)系統會解決此問題。

           sub makeone {
               my @a = ( 1 .. 10 );
               return \@a;
           }

           for ( 1 .. 10 ) {
               push @many, makeone();
           }

           print $many[4][5], "\n";

           print "@many\n";

      p@CHYp{o?

       你無法這麼作。系統配置給程式的記憶體是覆水難收。這也是為何執行很長一段時間的程式有時會-
       奐s執行 (re-exec)它怞菑v的鴞]。 Some operating systems (notably,
       systems that use mmap(2) for allocating large chunks of memory) can
       reclaim memory that is no longer used, but on such systems, perl must
       be configured and compiled to use the OS's malloc, not perl's.

       然而,在使用你的變數時,明智地用 my()來定義執行S圍,可讓 Perl在脫離該-
       S圍後 將它怍狾的空間釋放給其它部份的程式。
       (注:my()的變數也比全域變數執行起來快 10%。)當然,一-
       茈域變數永遠沒有超出S圍的時唌A所以你無法將它佔用的空間自動-
       奐s分配,不過,把它 undef() 或/和 delete()會有相同的效果。總之,在
       Perl裏,你並不能/應該去擔心太多有關記憶體定址與解除這件事,而我-
       抭s添加這項功能(資料形態的預先定址),目前都已在進行中。

      p CGI(script)v?

       除了使一般 Perl程式加快或縮小的弗`手段外,一 CGI
       程式還有其他的顧慮。也許它每秒會被執行好幾次。每次它執行時,-
       奐s編譯所花的時間、加上定址所需的 1 MB以上的系統記憶體,就是一-
       茪j殺手。光是編譯成 C 是沒啥幫助的 ,因為瓶頸在於整茧{式開始時所-
       t擔的包袱 (start-up overhead) 。

       最起碼有兩種較流行的方法可以避免這些包袱。一種解法是將 mod_perl 或是
       mod_fastcgi其中一蚍珩掍[在你所執行的 Apache HTTP server。

       有了 mod_perl 和 Apache::*模組 (從 CPAN取得),httpd執行時會帶起一茪
       嵌的
       Perl直譯器,而它會預先編譯你的程式,並在不產生其它子程式的情況下用同一-
       茤w址空間來執行。Apache 擴充模組亦給 Perl一茬s通 server API
       的管道,所以用 Perl寫的模組可以做到任何
       C寫的模組所具備的功能。詳情請參閱 http://perl.apache.org/

       而有了 FCGI模組 (自 CPAN取得) 和 mod_fastcgi 模塊(從
       http://www.fastcgi.com/取得),每 Perl 程式將成為一茈瓣[的 CGI
       守護進程。

       這些方法對你的系統與你撰寫
       CGI程式的方法都有超乎想像之外的影響,所以請小心地使用它怴C

       參見
       http://www.cpan.org/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/
       .

       A non-free, commercial product, ``The Velocity Engine for Perl'',
       (http://www.binevolve.com/ or http://www.binevolve.com/velocigen/ )
       might also be worth looking at.  It will allow you to increase the
       performance of your Perl programs, running programs up to 25 times
       faster than normal CGI Perl when running in persistent Perl mode or 4
       to 5 times faster without any modification to your existing CGI
       programs. Fully functional evaluation copies are available from the web
       site.

      p Perl?

       刪除它。 :-)
       說真的,有一些具有不同「安全」等級的方法(大部分都不能令人滿意)。

       漸,你 不能拿走讀取權,不然你的程式怎麼被解譯或是編譯呢?
       (不過那也並不表示一 CGI程式的鴝l碼可以被使用者讀取。)所以你得讓檔案權-
       停留在 0755這茪芚蔽熄布q。

       有些人認為這是茼w全上的漏洞。不過-
       Y你的程式作的是不安全的事情,光仰賴別人看不見這些漏洞、不知從何下手,那麼它依然是不安全的。其實對有些人來說他-
       怢瓣˙愯看見程式-
       鴝l碼便可能判定並揭露這些不安全的部份。透過隱瞞達到的安全,就是不-
       蚰膳鞃峇浀蚆蘌疇米,實際上是沒有安全性可言的。

       你可以試著透過鴝l碼過濾模組 (CPAN中的 Filter::*)來替-
       鴝l碼加密。但高手也許有辦法將其解密還魽C你也可以用下探ㄗ鴘 byte code
       編譯器與直譯器,但高手也有可能反解譯它。你可以試試後探ㄗ鴘綻生碼編譯器
       (native-code compiler),但高手也有可能反組譯它。這些手段都需-
       n不同難度的技巧才能讓別人拿到你的-
       鴝l碼,但沒有一種能夠很確定地隱藏它。(這對每種語言來說都為真,不是只有
       Perl)

       很容易從 Perl 程式中恢復出鴝l碼。只n將程式作為 perl
       解釋器的參數,並且使用 B:: 中的模塊就可以了。B::Deparse
       模塊足以恢復大多數隱藏的代碼。再次的,這不是 Perl 特有的東西。

       如果你所擔心的是別人自你的程式碼中獲利,那麼一紙權-
       執照是能提供你法律上安全的唯一途徑。注冊你的軟體並且寫份權-
       說明,再加上一些具威脅性的句子像「這是
       XYZ公司未出版的專有軟體。你能擷取它並不代表你具有使用的權-
       ...」之類雲雲。當然,我怳ㄛO律師,所以Y你想-
       n你的執照中每一句話在法庭上都站得住腳,就去見茷蒏v吧。

      p Perlbyte codeC?

       Malcolm Beattie已經寫了一茼h功能的後端編譯器,可以從
       CPAN取得,它就能做到這兩項功能。它包含在 perl5.005
       發佈中,但是仍然是測試版。這代表著Y你是茧{式設p
       而非尋找萬靈解藥的人,那麼參與其測試就會充滿趣味。

       請了解光是編譯成 C 其本-
       或在本質上並不能保証它就會跑得快更多。那是因為除了在運氣好的狀況中有一堆可以-
       l生成出來的鴠竻庥A外,幼阞 Perl
       執行系統環境依然存在因此依然會花差不多長的執行時間與佔用差不多大小的記憶空間。大多數程式能省下來的不過是編譯時間,這使執行速度頂多快
       10-30%。有些罕見的程式能真正從中受利 (例如增快好幾),但這還得配合-
       鴝l碼的微調。

       你或許會驚訝地發現,現行版本的編譯器做出來的執行檔大小跟你的
       Perl直譯器一樣大,有時更大些。那是因為依照現在的寫法,所有的程式皆轉成一-
       茬Q eval()的大敘z。只n建造一荌妧A連結的
       libperl.so程式庫,並將之連結起來,你就可以戲劇性地減少這 種浪費。參看
       perl鴝l碼套件中的 INSTALL
       pod檔案以獲得更詳盡的訊息。如果你用這方法連結你主n的
       perl執行檔,就能使它變得很渺小。舉例來說,在作者之一的系 統裏,
       /usr/bin/perl只有 11k「小」而已!

       In general, the compiler will do nothing to make a Perl program
       smaller, faster, more portable, or more secure.  In fact, it can make
       your situation worse.  The executable will be bigger, your VM system
       may take longer to load the whole thing, the binary is fragile and hard
       to fix, and compilation never stopped software piracy in the form of
       crackers, viruses, or bootleggers.  The real advantage of the compiler
       is merely packaging, and once you see the size of what it makes (well,
       unless you use a shared libperl.so), you'll probably want a complete
       Perl install anyway.

       How can I compile Perl into Java?

       You can also integrate Java and Perl with the Perl Resource Kit from
       O'Reilly and Associates.  See http://www.oreilly.com/catalog/prkunix/ .

       Perl 5.6 comes with Java Perl Lingo, or JPL.  JPL, still in
       development, allows Perl code to be called from Java.  See jpl/README
       in the Perl source tree.

      p~讓

       OS/2下只n用:

           extproc perl -S -your_switches

       當作 "*.cmd" 檔案的第一行 ("-S" 是因 cmd.exe中其 `extproc'處理的臭蟲才-
       n的)。DOS使用者應先製作一茯蛫麊 batch 檔案然後將它以
       ALTERNATIVE_SHEBANG 的方式寫成程式。(更多訊息在鴝l碼版本的
       INSTALL檔案裏)

       The Win95/NT installation, when using the ActiveState port of Perl,
       will modify the Registry to associate the ".pl" extension with the perl
       interpreter.  If you install another port, perhaps even building your
       own Win95/NT Perl from the standard sources by using a Windows port of
       gcc (e.g., with cygwin or mingw32), then you'll have to modify the
       Registry yourself.  In addition to associating ".pl" with the
       interpreter, NT people can use: "SET PATHEXT=%PATHEXT%;.PL" to let them
       run the program "install-linux.pl" merely by typing "install-linux".

       麥金塔的 perl程式將會有適當的創造者與形態 (Creator and
       Type),所以雙擊它抴N會執行這些 perl 應用程式。

       南:不論你做什麼,請千萬不n因為覺得沮喪,就把 perl 直譯器丟到你的 cgi-
       bin目錄下,好讓你的 web 伺服器能執行你的程式。這是一-
       茷D常大的安全漏洞。花點時間想想怎樣才是正確的做法吧。

      QROgX{?

       可以。詳情請看 perlrun。以下有些範例 (假設用的是標準的 Unix
       shell引言規則)。

           # 把第一欄和最後一欄相加
           perl -lane 'print $F[0] + $F[-1]' *

           # 辨別是否為文字檔
           perl -le 'for(@ARGV) {print if -f && -T _}' *

           # 移除 C程式中的說明
           perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c

           # 讓檔案年輕一茪諢A躲避 reaper daemons
           perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' *

           # 找出第一茈憧峈 uid
           perl -le '$i++ while getpwuid($i); print $i'

           # 顯示合理的使用說明路徑 (manpath)
           echo $PATH | perl -nl -072 -e '
               s![^/+]*$!man!&&-d&&!$s{$_}++&&push@m,$_;END{print"@m"}'

       好吧,最後一茖狺l事實上是「perl程式困惑化」競賽 (Obfuscated Perl)的
       參賽作品。 :-)

      @ perl{Lkb DOS/Mac/VMS?

       問題通常出在那些系統的命令解譯器對於參數的引用與 Unix shells
       所作的解釋不同,而後者很不幸的是這些一行 perl
       的生父。在某些系統,也許你得把單引號改成雙引號,但這卻是你萬萬 不可在
       Unix或 Plan9系統上作的事。你也許還得把一 %改成 %%。

       例如:

           # Unix
           perl -e 'print "Hello world\n"'

           # DOS 和其他機器
           perl -e "print \"Hello world\n\""

           # Mac
           print "Hello world\n"
            (然後運行 "Myscript" 或按 Shift-Command-R)

           # MPW
           perl -e 'print "Hello world\n"'

           # VMS
           perl -e "print ""Hello world\n"""

       問題是,這些方法沒有一茯O完全可靠的:它都得看命令解譯器的臉色。在
       Unix中,前兩者通常可以用。在 DOS下,兩者可能都沒有用。Y
       4DOS是命令解譯器,下惘鼓k可能比 較有希望:

         perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""

       在 Mac 下,端視你所用的環境為何。 MacPerl所附的 shell,或是 MPW,
       其所支援的參數格式有不少都蠻像 Unix shells的,除了它自在地使用 Mac 的非
       ASCII字元當成控制字元。

       Using qq(), q(), and qx(), instead of "double quotes", 'single quotes',
       and `backticks`, may make one-liners easier to write.

       恐怕我得說這問題並沒有一般解。白話一點說,它真是一團亂。

       [部份答案是由 Kenneth Albanowski 所提供的。]

      oh PerlCGIWebp?

       就模組來說,去 CPAN抓 CGI 和 LWP 兩-
       蚍珩捸C就書本來看,參考關於書那部份裏特別和 web 相關的問題。Y有與
       web相關的疑難雜症,像「為何我收到
       500錯誤」或「它在命令列模式下跑得好好的,怎麼不能在瀏覽器下正常執行」時,請參看:

               http://www.perl.org/CGI_MetaFAQ.html

      qiHVH Perls{H

       perltoot是茼n開始,然後你可以再參考 perlobj 和
       perlboot,Perltoot,perltooc 以及 perlbot (如果你使用老版本的
       Perl,你可能沒有這些。去 http://www.perldoc.com/ 下載吧,但是-
       漸考慮一下升級你的 perl)

       有本好書關於 Perl 中的 OO 是 "Object-Oriented Perl" 作者是 Damian
       Conway ,出版社為 Manning Publications,
       http://www.manning.com/Conway/index.html

      qiHN PerlP CsH[h2xs, xsubpp]

       Y你n從 Perl程式呼叫 C,就自 perlxstut開始向 perlxs ,xsubpp ,及
       perlguts前進。反之,則讀 perlembed ,perlcall ,及 perlguts
       。別忘了你可以從各模組的作者如何寫他怐獐珩掑庛悃M他怐滌暋D中學到很多。

      wgF perlembed,perlgutsAOOb C{OJ
       perlWhat's MakeMaker?

       此模組 (亦為標準 perl 套件之一部份)設p的目的是n替一蚍珩梇q一
       Makefile.PL 中自動撰寫出一 Makefile。詳情請看 ExtUtils::MakeMaker。

AUTHOR AND COPYRIGHT

       Copyright (c) 1997-2002 Tom Christiansen and Nathan Torkington.  All
       rights reserved.

       This documentation is free; you can redistribute it and/or modify it
       under the same terms as Perl itself.

       Irrespective of its distribution, all code examples here are in the
       public domain.  You are permitted and encouraged to use this code and
       any derivatives thereof in your own programs for fun or for profit as
       you see fit.  A simple comment in the code giving credit to the FAQ
       would be courteous but is not required.

者
       陳彥銘,蕭百齡,兩只老虎工作室