perlfaq3.pod
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 1,055 行 · 第 1/3 页
POD
1,055 行
=over 4=item Elvisftp://ftp.cs.pdx.edu/pub/elvis/ http://www.fh-wedel.de/elvis/=item Vilehttp://dickey.his.com/vile/vile.html=item Vimhttp://www.vim.org/=backFor vi lovers in general, Windows or elsewhere: http://www.thomer.com/thomer/vi/vi.htmlnvi ( http://www.bostic.com/vi/ , available from CPAN in src/misc/) isyet another vi clone, unfortunately not available for Windows, but inUNIX platforms you might be interested in trying it out, firstly becausestrictly speaking it is not a vi clone, it is the real vi, or the newincarnation of it, and secondly because you can embed Perl inside itto 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:=over 4=item Codewrighthttp://www.borland.com/codewright/=item MultiEdithttp://www.MultiEdit.com/=item SlickEdithttp://www.slickedit.com/=backThere is also a toyedit Text widget based editor written in Perlthat is distributed with the Tk module on CPAN. The ptkdb( http://ptkdb.sourceforge.net/ ) is a Perl/tk based debugger thatacts as a development environment of sorts. Perl Composer( http://perlcomposer.sourceforge.net/ ) 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 Zshhttp://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 Affrusis a full Perl development environment with full debugger support( http://www.latenightsw.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://www.his.com/~jguyer/Alpha/Alpha8.html ).=item BBEdit and BBEdit Liteare text editors for Mac OS that have a Perl sensitivity mode( http://web.barebones.com/ ).=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.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 builtwith an embedded Perl interpreter--see http://www.cpan.org/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.cpan.org/authors/Tom_Christiansen/scripts/rep.gz ;this program repeats a command and updates the screen as needed, renderingB<rep ps axu> similar to B<top>.=head2 How can I write a GUI (X, Tk, Gtk, etc.) in Perl?X<GUI> X<Tk> X<Wx> X<WxWidgets> X<Gtk> X<Gtk2> X<CamelBones> X<Qt>(contributed by Ben Morrow)There are a number of modules which let you write GUIs in Perl. MostGUI toolkits have a perl interface: an incomplete list follows.=over 4=item TkThis works under Unix and Windows, and the current version doesn'tlook half as bad under Windows as it used to. Some of the gui elementsstill don't 'feel' quite right, though. The interface is very naturaland 'perlish', making it easy to use in small scripts that just need asimple gui. It hasn't been updated in a while.=item WxThis is a Perl binding for the cross-platform wxWidgets toolkit L<http://www.wxwidgets.org>. It works under Unix, Win32 and Mac OS X,using native widgets (Gtk under Unix). The interface follows the C++interface closely, but the documentation is a little sparse for someonewho doesn't know the library, mostly just referring you to the C++documentation.=item Gtk and Gtk2These are Perl bindings for the Gtk toolkit L<http://www.gtk.org>. Theinterface changed significantly between versions 1 and 2 so they haveseparate Perl modules. It runs under Unix, Win32 and Mac OS X (currentlyit requires an X server on Mac OS, but a 'native' port is underway), andthe widgets look the same on every plaform: i.e., they don't match thenative widgets. As with Wx, the Perl bindings follow the C API closely,and the documentation requires you to read the C documentation tounderstand it.=item Win32::GUIThis provides access to most of the Win32 GUI widgets from Perl.Obviously, it only runs under Win32, and uses native widgets. The Perlinterface doesn't really follow the C interface: it's been made morePerlish, and the documentation is pretty good. More advanced stuff mayrequire familiarity with the C Win32 APIs, or reference to MSDN.=item CamelBonesCamelBones L<http://camelbones.sourceforge.net> is a Perl interface toMac OS X's Cocoa GUI toolkit, and as such can be used to produce nativeGUIs on Mac OS X. It's not on CPAN, as it requires frameworks thatCPAN.pm doesn't know how to install, but installation is via thestandard OSX package installer. The Perl API is, again, very close tothe ObjC API it's wrapping, and the documentation just tells you how totranslate from one to the other.=item QtThere is a Perl interface to TrollTech's Qt toolkit, but it does notappear to be maintained.=item AthenaSx is an interface to the Athena widget set which comes with X, butagain it appears not to be much used nowadays.=back=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 bookI<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. You will probably want toread the answer to the earlier question "How do I profile my Perlprograms?" if you haven't done so already.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 havecritical sections can be written in C (for instance, the PDL modulefrom CPAN).If you're currently linking your perl executable to a sharedI<libc.so>, you can often gain a 10-25% performance benefit byrebuilding it to link with a static libc.a instead. This will make abigger perl executable, but your Perl programs (and programmers) maythank you for it. See the F<INSTALL> file in the source distributionfor more information.The undump program was an ancient attempt to speed up Perl program bystoring the already-compiled form to disk. This is no longer a viableoption, as it only worked on a few architectures, and wasn't a goodsolution 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>.Of course, the best way to save memory is to not do anything to wasteit in the first place. Good programming practices can go a long waytoward this:=over 4=item * Don't slurp!Don't read an entire file into memory if you can process it lineby 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 whichway you do it, but it makes a huge difference when they start gettinglarger.=item * Use map and grep selectivelyRemember 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 betterto loop: while (<FILE>) { push(@wanted, $_) if /pattern/; }=item * Avoid unnecessary quotes and stringificationDon't quote large strings unless absolutely necessary: my $copy = "$large_string";makes 2 copies of $large_string (one for $copy and another for thequotes), 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"; }=item * Pass by reference
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?