perlfaq3.pod

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 1,055 行 · 第 1/3 页

POD
1,055
字号
=head1 NAMEperlfaq3 - Programming Tools ($Revision: 10127 $)=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 manpages?  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.cpan.org/misc/olddoc/FMTEYEWTK.tgz			(not a man-page but still useful, a collection			 of various essays on Perl techniques)A crude table of contents for the Perl manpage set is found in L<perltoc>.=head2 How can I use Perl interactively?The typical approach uses the Perl debugger, described in theperldebug(1) manpage, 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?The psh (Perl sh) is currently at version 1.8. The Perl Shell is a shellthat combines the interactive nature of a Unix shell with the power ofPerl. The goal is a full featured shell that behaves as expected fornormal shell activity and uses Perl syntax and functionality forcontrol-flow statements and other things. You can get psh athttp://sourceforge.net/projects/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 shelland 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 commandswhich aren't part of the Perl language as shell commands.  perlsh fromthe source distribution is simplistic and uninteresting, but may stillbe what you want.=head2 How do I find which modules are installed on my system?You can use the ExtUtils::Installed module to show all installeddistributions, although it can take awhile to do its magic.  Thestandard library which comes with Perl just shows up as "Perl" (althoughyou 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, youcan 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 thingwith File::Find which is part of the standard library.    use File::Find;    my @files;    find(      sub {      	push @files, $File::Find::name      		if -f $File::Find::name && /\.pm$/      	},      @INC      );	print join "\n", @files;If you simply need to quickly check to see if a module isavailable, you can check for its documentation.  If you canread the documentation the module is most likely installed.If you cannot read the documentation, the module might nothave any (in rare cases).	prompt% perldoc Module::NameYou can also try to include the module in a one-liner to see ifperl finds it.	perl -MModule::Name -e1=head2 How do I debug my Perl programs?(contributed by brian d foy)Before you do anything else, you can help yourself by ensuring thatyou let Perl tell you about problem areas in your code. By turningon warnings and strictures, you can head off many problems beforethey get too big. You can find out more about these in L<strict>and L<warnings>.	#!/usr/bin/perl	use strict;	use warnings;Beyond that, the simplest debugger is the C<print> function. Use itto look at values as you run your program:	print STDERR "The value is [$value]\n";The C<Data::Dumper> module can pretty-print Perl data structures:	use Data::Dumper qw( Dumper );	print STDERR "The hash is " . Dumper( \%hash ) . "\n";Perl comes with an interactive debugger, which you can start with theC<-d> switch. It's fully explained in L<perldebug>.If you'd like a graphical user interface and you have Tk, you can useC<ptkdb>. It's on CPAN and available for free.If you need something much more sophisticated and controllable, LeonBrocard's Devel::ebug (which you can call with the -D switch as -Debug)gives you the programmatic hooks into everything you need to write yourown (without too much pain and suffering).You can also use a commercial debugger such as Affrus (Mac OS X), Komodofrom Activestate (Windows and Mac OS X), or EPIC (most platforms).=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 standarddistribution.  The Benchmark module lets you time specific portions ofyour code, while Devel::DProf gives detailed breakdowns of where yourcode 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;			   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 can be used to generate cross-reference reportsfor Perl programs.    perl -MO=Xref[,OPTIONS] scriptname.plx=head2 Is there a pretty-printer (formatter) for Perl?Perltidy is a Perl script which indents and reformats Perl scriptsto make them easier to read by trying to follow the rules of theL<perlstyle>. If you write Perl scripts, or spend much time readingthem, you will probably find it useful.  It is available athttp://perltidy.sourceforge.netOf course, if you simply follow the guidelines in L<perlstyle>,you shouldn't need to reformat.  The habit of formatting your codeas you write it will help prevent bugs.  Your editor can and shouldhelp you with this.  The perl-mode or newer cperl-mode for emacscan provide remarkable amounts of help with most (but not all)code, and even less programmable editors can provide significantassistance.  Tom Christiansen and many other VI users  swear bythe following settings in vi and its clones:    set ai sw=4    map! ^O {^M}^[O^TPut 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--asit were.  A more complete example, with comments, can be found athttp://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gzThe a2ps http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz doeslots of things related to generating nicely printed output ofdocuments.=head2 Is there a ctags for Perl?(contributed by brian d foy)Ctags uses an index to quickly find things in source code, and manypopular editors support ctags for several different languages,including Perl.Exuberent ctags supports Perl: http://ctags.sourceforge.net/You might also try pltags: http://www.mscha.com/pltags.zip=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 an IDE, check the following (in alphabetical order, notorder of preference):=over 4=item Eclipsehttp://e-p-i-c.sf.net/The Eclipse Perl Integration Project integrates Perlediting/debugging with Eclipse.=item Enginsitehttp://www.enginsite.com/Perl Editor by EngInSite is a complete integrated developmentenvironment (IDE) for creating, testing, and  debugging  Perl scripts;the tool runs on Windows 9x/NT/2000/XP or later.=item Komodohttp://www.ActiveState.com/Products/Komodo/ActiveState's cross-platform (as of October 2004, that's Windows, Linux,and Solaris), multi-language IDE has Perl support, including a regular expressiondebugger and remote debugging.=item Open Perl IDEhttp://open-perl-ide.sourceforge.net/Open Perl IDE is an integrated development environment for writingand debugging Perl scripts with ActiveState's ActivePerl distributionunder Windows 95/98/NT/2000.=item OptiPerlhttp://www.optiperl.com/OptiPerl is a Windows IDE with simulated CGI environment, includingdebugger and syntax highlighting editor.=item PerlBuilderhttp://www.solutionsoft.com/perl.htmPerlBuidler is an integrated development environment for Windows thatsupports Perl development.=item visiPerl+http://helpconsulting.net/visiperl/From Help Consulting, for Windows.=item Visual Perlhttp://www.activestate.com/Products/Visual_Perl/Visual Perl is a Visual Studio.NET plug-in from ActiveState.=item Zeushttp://www.zeusedit.com/lookmain.htmlZeus for Window is another Win32 multi-language editor/IDEthat comes with support for Perl:=backFor editors: if you're on Unix you probably have vi or a vi clonealready, and possibly an emacs too, so you may not need to downloadanything. In any emacs the cperl-mode (M-x cperl-mode) gives youperhaps the best available Perl editing mode in any editor.If you are using Windows, you can use any editor that lets you workwith plain text, such as NotePad or WordPad.  Word processors, such asMicrosoft Word or WordPerfect, typically do not work since they insertall sorts of behind-the-scenes information, although some allow you tosave files as "Text Only". You can also download text editors designedspecifically 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 Classicenvironments) comes with a simple editor. Popular external editors areBBEdit ( http://www.bbedit.com/ ) or Alpha (http://www.his.com/~jguyer/Alpha/Alpha8.html ). MacOS X users can useUnix editors as well.=over 4=item GNU Emacshttp://www.gnu.org/software/emacs/windows/ntemacs.html=item MicroEMACShttp://www.microemacs.de/=item XEmacshttp://www.xemacs.org/Download/index.html=item Jedhttp://space.mit.edu/~davis/jed/=backor a vi clone such as

⌨️ 快捷键说明

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