📄 perlfaq.pod
字号:
There is also a toyedit Text widget based editor written in Perlthat is distributed with the Tk module on CPAN. The ptkdb(http://world.std.com/~aep/ptkdb/) is a Perl/tk based debugger thatacts as a development environment of sorts. Perl Composer(http://perlcomposer.sourceforge.net/vperl.html) is an IDE for Perl/TkGUI creation.In addition to an editor/IDE you might be interested in a morepowerful shell environment for Win32. Your options include=over 4=item Bashfrom the Cygwin package (http://sources.redhat.com/cygwin/)=item Kshfrom the MKS Toolkit (http://www.mks.com/), or the Bourne shell ofthe U/WIN environment (http://www.research.att.com/sw/tools/uwin/)=item Tcshftp://ftp.astron.com/pub/tcsh/, see alsohttp://www.primate.wisc.edu/software/csh-tcsh-book/=item Zshftp://ftp.blarg.net/users/amol/zsh/, see also http://www.zsh.org/=backMKS and U/WIN are commercial (U/WIN is free for educational andresearch purposes), Cygwin is covered by the GNU Public License (butthat shouldn't matter for Perl use). The Cygwin, MKS, and U/WIN allcontain (in addition to the shells) a comprehensive set of standardUNIX toolkit utilities.If you're transferring text files between Unix and Windows using FTPbe sure to transfer them in ASCII mode so the ends of lines areappropriately converted.On Mac OS the MacPerl Application comes with a simple 32k text editorthat behaves like a rudimentary IDE. In contrast to the MacPerl Applicationthe MPW Perl tool can make use of the MPW Shell itself as an editor (withno 32k limit).=over 4=item BBEdit and BBEdit Liteare text editors for Mac OS that have a Perl sensitivity mode(http://web.barebones.com/).=item Alphais an editor, written and extensible in Tcl, that nonetheless hasbuilt in support for several popular markup and programming languagesincluding Perl and HTML (http://alpha.olm.net/).=backPepper and Pe are programming language sensitive text editors for MacOS X and BeOS respectively (http://www.hekkelman.com/).=head2 Where can I get Perl macros for vi?For a complete version of Tom Christiansen's vi configuration file,see http://www.perl.com/CPAN/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 builtwith an embedded Perl interpreter--see http://www.perl.com/CPAN/src/misc.=head2 Where can I get perl-mode for emacs?Since Emacs version 19 patchlevel 22 or so, there have been both aperl-mode.el and support for the Perl debugger built in. These shouldcome with the standard Emacs 19 distribution.In the Perl source directory, you'll find a directory called "emacs",which contains a cperl-mode that color-codes keywords, providescontext-sensitive help, and other nifty things.Note that the perl-mode of emacs will have fits with C<"main'foo">(single quote), and mess up the indentation and highlighting. Youare probably using C<"main::foo"> in new Perl code anyway, so thisshouldn't be an issue.=head2 How can I use curses with Perl?The Curses module from CPAN provides a dynamically loadable objectmodule interface to a curses library. A small demo can be found at thedirectory http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/rep;this program repeats a command and updates the screen as needed, renderingB<rep ps axu> similar to B<top>.=head2 How can I use X or Tk with Perl?Tk is a completely Perl-based, object-oriented interface to the Tk toolkitthat doesn't force you to use Tcl just to get at Tk. Sx is an interfaceto the Athena Widget set. Both are available from CPAN. See thedirectory http://www.perl.com/CPAN/modules/by-category/08_User_Interfaces/Invaluable for Perl/Tk programming are the Perl/Tk FAQ athttp://w4.lns.cornell.edu/%7Epvhp/ptk/ptkTOC.html , the Perl/Tk ReferenceGuide available athttp://www.perl.com/CPAN-local/authors/Stephen_O_Lidie/ , and theonline manpages athttp://www-users.cs.umn.edu/%7Eamundson/perl/perltk/toc.html .=head2 How can I generate simple menus without using CGI or Tk?The http://www.perl.com/CPAN/authors/id/SKUNZ/perlmenu.v4.0.tar.gzmodule, which is curses-based, can help with this.=head2 What is undump?See the next question on ``How can I make my Perl program run faster?''=head2 How can I make my Perl program run faster?The best way to do this is to come up with a better algorithm. Thiscan often make a dramatic difference. Jon Bentley's book``Programming Pearls'' (that's not a misspelling!) has some good tipson optimization, too. Advice on benchmarking boils down to: benchmarkand profile to make sure you're optimizing the right part, look forbetter algorithms instead of microtuning your code, and when all elsefails consider just buying faster hardware.A different approach is to autoload seldom-used Perl code. See theAutoSplit and AutoLoader modules in the standard distribution forthat. Or you could locate the bottleneck and think about writing justthat part in C, the way we used to take bottlenecks in C code andwrite them in assembler. Similar to rewriting in C,modules that have critical sections can be written in C (for instance, thePDL module from CPAN).In some cases, it may be worth it to use the backend compiler toproduce byte code (saving compilation time) or compile into C, whichwill certainly save compilation time and sometimes a small amount (butnot much) execution time. See the question about compiling your Perlprograms for more on the compiler--the wins aren't as obvious as you'dhope.If you're currently linking your perl executable to a shared I<libc.so>,you can often gain a 10-25% performance benefit by rebuilding it tolink with a static libc.a instead. This will make a bigger perlexecutable, but your Perl programs (and programmers) may thank you forit. See the F<INSTALL> file in the source distribution for moreinformation.Unsubstantiated reports allege that Perl interpreters that use sfiooutperform those that don't (for I/O intensive applications). To trythis, see the F<INSTALL> file in the source distribution, especiallythe ``Selecting File I/O mechanisms'' section.The undump program was an old attempt to speed up your Perl programby storing the already-compiled form to disk. This is no longera viable option, as it only worked on a few architectures, andwasn't a good solution anyway.=head2 How can I make my Perl program take less memory?When it comes to time-space tradeoffs, Perl nearly always prefers tothrow memory at a problem. Scalars in Perl use more memory thanstrings in C, arrays take more than that, and hashes use even more. Whilethere's still a lot to be done, recent releases have been addressingthese issues. For example, as of 5.004, duplicate hash keys areshared amongst all hashes using them, so require no reallocation.In some cases, using substr() or vec() to simulate arrays can behighly beneficial. For example, an array of a thousand booleans willtake at least 20,000 bytes of space, but it can be turned into one125-byte bit vector--a considerable memory savings. The standardTie::SubstrHash module can also help for certain types of datastructure. If you're working with specialist data structures(matrices, for instance) modules that implement these in C may useless memory than equivalent Perl modules.Another thing to try is learning whether your Perl was compiled withthe system malloc or with Perl's builtin malloc. Whichever one itis, try using the other one and see whether this makes a difference.Information about malloc is in the F<INSTALL> file in the sourcedistribution. You can find out whether you are using perl's malloc bytyping C<perl -V:usemymalloc>.=head2 Is it unsafe to return a pointer to local data?No, Perl's garbage collection system takes care of this. sub makeone { my @a = ( 1 .. 10 ); return \@a; } for $i ( 1 .. 10 ) { push @many, makeone(); } print $many[4][5], "\n"; print "@many\n";=head2 How can I free an array or hash so my program shrinks?You can't. On most operating systems, memory allocated to a programcan never be returned to the system. That's why long-running programssometimes re-exec themselves. Some operating systems (notably,FreeBSD and Linux) allegedly reclaim large chunks of memory that is nolonger used, but it doesn't appear to happen with Perl (yet). The Macappears to be the only platform that will reliably (albeit, slowly)return memory to the OS.We've had reports that on Linux (Redhat 5.1) on Intel, C<undef$scalar> will return memory to the system, while on Solaris 2.6 itwon't. In general, try it yourself and see.However, judicious use of my() on your variables will help make surethat they go out of scope so that Perl can free up that space foruse in other parts of your program. A global variable, of course, nevergoes out of scope, so you can't get its space automatically reclaimed,although undef()ing and/or delete()ing it will achieve the same effect.In general, memory allocation and de-allocation isn't something you canor should be worrying about much in Perl, but even this capability(preallocation of data types) is in the works.=head2 How can I make my CGI script more efficient?Beyond the normal measures described to make general Perl programsfaster or smaller, a CGI program has additional issues. It may be runseveral times per second. Given that each time it runs it will needto be re-compiled and will often allocate a megabyte or more of systemmemory, this can be a killer. Compiling into C B<isn't going to helpyou> because the process start-up overhead is where the bottleneck is.There are two popular ways to avoid this overhead. One solutioninvolves running the Apache HTTP server (available fromhttp://www.apache.org/) with either of the mod_perl or mod_fastcgiplugin modules.With mod_perl and the Apache::Registry module (distributed withmod_perl), httpd will run with an embedded Perl interpreter whichpre-compiles your script and then executes it within the same addressspace without forking. The Apache extension also gives Perl access tothe internal server API, so modules written in Perl can do just aboutanything a module written in C can. For more on mod_perl, seehttp://perl.apache.org/With the FCGI module (from CPAN) and the mod_fastcgimodule (available from http://www.fastcgi.com/) each of your Perlprograms becomes a permanent CGI daemon process.Both of these solutions can have far-reaching effects on your systemand on the way you write your CGI programs, so investigate them withcare.See http://www.perl.com/CPAN/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 theperformance of your Perl programs, running programs up to 25 timesfaster than normal CGI Perl when running in persistent Perl mode or 4to 5 times faster without any modification to your existing CGIprograms. Fully functional evaluation copies are available from theweb site.=head2 How can I hide the source for my Perl program?Delete it. :-) Seriously, there are a number of (mostlyunsatisfactory) solutions with varying levels of ``security''.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -