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

📄 perlfaq.pod

📁 source of perl for linux application,
💻 POD
📖 第 1 页 / 共 3 页
字号:
=head1 NAMEperlfaq3 - Programming Tools ($Revision: 1.38 $, $Date: 1999/05/23 16:08:30 $)=head1 DESCRIPTIONThis section of the FAQ answers questions related to programmer toolsand programming support.=head2 How do I do (anything)?Have you looked at CPAN (see L<perlfaq2>)?  The chances are thatsomeone has already written a module that can solve your problem.Have you read the appropriate man pages?  Here's a brief index:	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.perl.com/CPAN/doc/FMTEYEWTK/index.html			(not a man-page but still useful)A crude table of contents for the Perl man page set is found in L<perltoc>.=head2 How can I use Perl interactively?The typical approach uses the Perl debugger, described in theperldebug(1) man page, on an ``empty'' program, like this:    perl -de 42Now just type in any legal Perl code, and it will be immediatelyevaluated.  You can also examine the symbol table, get stackbacktraces, check variable values, set breakpoints, and otheroperations typically found in symbolic debuggers.=head2 Is there a Perl shell?In general, no.  The Shell.pm module (distributed with Perl) makesPerl try commands which aren't part of the Perl language as shellcommands.  perlsh from the source distribution is simplistic anduninteresting, but may still be what you want.=head2 How do I debug my Perl programs?Have you tried C<use warnings> or used C<-w>?  They enable warnings to detect dubious practices.Have you tried C<use strict>?  It prevents you from using symbolicreferences, makes you predeclare any subroutines that you call as barewords, and (probably most importantly) forces you to predeclare yourvariables with C<my>, C<our>, or C<use vars>.Did you check the return values of each and every system call?  The operatingsystem (and thus Perl) tells you whether they worked, and if notwhy.  open(FH, "> /etc/cantwrite")    or die "Couldn't write to /etc/cantwrite: $!\n";Did you read L<perltrap>?  It's full of gotchas for old and new Perlprogrammers and even has sections for those of you who are upgradingfrom languages like I<awk> and I<C>.Have you tried the Perl debugger, described in L<perldebug>?  You canstep through your program and see what it's doing and thus work outwhy what it's doing isn't what it should be doing.=head2 How do I profile my Perl programs?You should get the Devel::DProf module from the standard distribution(or separately on CPAN) and also use Benchmark.pm from the standard distribution.  The Benchmark module lets you time specific portions of your code, while Devel::DProf gives detailed breakdowns of where your code spends its time.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;			   local $_;			   for (@a) { s/a/b/ };			   return @a },           });This is what it prints (on one machine--your results will be dependenton 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 thedata you give it and proves little about the differing complexitiesof contrasting algorithms.=head2 How do I cross-reference my Perl programs?The B::Xref module, shipped with the new, alpha-release Perl compiler(not the general distribution prior to the 5.005 release), can be usedto generate cross-reference reports for Perl programs.    perl -MO=Xref[,OPTIONS] scriptname.plx=head2 Is there a pretty-printer (formatter) for Perl?There is no program that will reformat Perl as much as indent(1) doesfor C.  The complex feedback between the scanner and the parser (thisfeedback is what confuses the vgrind and emacs programs) makes itchallenging at best to write a stand-alone Perl parser.Of course, if you simply follow the guidelines in L<perlstyle>, youshouldn't need to reformat.  The habit of formatting your code as youwrite it will help prevent bugs.  Your editor can and should help youwith this.  The perl-mode or newer cperl-mode for emacs can provideremarkable amounts of help with most (but not all) code, and even lessprogrammable editors can provide significant assistance.  Tom swearsby the following settings in vi and its clones:    set ai sw=4    map! ^O {^M}^[O^TNow put that in your F<.exrc> file (replacing the caret characterswith control characters) and away you go.  In insert mode, ^T isfor indenting, ^D is for undenting, and ^O is for blockdenting--as it were.  If you haven't used the last one, you're missinga lot.  A more complete example, with comments, can be found athttp://www.perl.com/CPAN-local/authors/id/TOMC/scripts/toms.exrc.gzIf you are used to using the I<vgrind> program for printing out nice codeto a laser printer, you can take a stab at this usinghttp://www.perl.com/CPAN/doc/misc/tips/working.vgrind.entry, but theresults are not particularly satisfying for sophisticated code.The a2ps at http://www.infres.enst.fr/%7Edemaille/a2ps/ does lots of thingsrelated to generating nicely printed output of documents.=head2 Is there a ctags for Perl?There's a simple one athttp://www.perl.com/CPAN/authors/id/TOMC/scripts/ptags.gz which may dothe trick.  And if not, it's easy to hack into what you want.=head2 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 UNIXphilosophy is the philosophy of several small tools that each do onething and do it well.  It's like a carpenter's toolbox.If you want a Windows IDE, check the following:=over 4=item CodeMagicCDhttp://www.codemagiccd.com/=item KomodoActiveState's cross-platform, 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)).=item The Object System(http://www.castlelink.co.uk/object_system/) is a Perl webapplications development IDE.=item PerlBuilder(http://www.solutionsoft.com/perl.htm) is an integrated developmentenvironment for Windows that supports Perl development.=item Perl code magic(http://www.petes-place.com/codemagic.html).=item visiPerl+http://helpconsulting.net/visiperl/, from Help Consulting.=backFor 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 thebest available Perl editing mode in any editor.For Windows editors: you can download an Emacs=over 4=item GNU Emacshttp://www.gnu.org/software/emacs/windows/ntemacs.html=item MicroEMACShttp://members.nbci.com/uemacs/=item XEmacshttp://www.xemacs.org/Download/index.html=backor a vi clone such as=over 4=item Elvisftp://ftp.cs.pdx.edu/pub/elvis/ http://www.fh-wedel.de/elvis/=item Vilehttp://vile.cx/=item Vimhttp://www.vim.org/win32: http://www.cs.vu.nl/%7Etmgil/vi.html=backFor 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/) 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.starbase.com/=item MultiEdithttp://www.MultiEdit.com/=item SlickEdithttp://www.slickedit.com/=back

⌨️ 快捷键说明

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