📄 perlfaq3.1
字号:
.PPThere are two popular ways to avoid this overhead. One solutioninvolves running the Apache \s-1HTTP\s0 server (available fromhttp://www.apache.org/ ) with either of the mod_perl or mod_fastcgiplugin modules..PPWith 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 \s-1API\s0, so modules written in Perl can do just aboutanything a module written in C can. For more on mod_perl, seehttp://perl.apache.org/.PPWith the \s-1FCGI\s0 module (from \s-1CPAN\s0) and the mod_fastcgimodule (available from http://www.fastcgi.com/ ) each of your Perlprograms becomes a permanent \s-1CGI\s0 daemon process..PPBoth of these solutions can have far-reaching effects on your systemand on the way you write your \s-1CGI\s0 programs, so investigate them withcare..PPSee http://www.cpan.org/modules/by\-category/15_World_Wide_Web_HTML_HTTP_CGI/ ..Sh "How can I hide the source for my Perl program?".IX Subsection "How can I hide the source for my Perl program?"Delete it. :\-) Seriously, there are a number of (mostlyunsatisfactory) solutions with varying levels of \*(L"security\*(R"..PPFirst of all, however, you \fIcan't\fR take away read permission, becausethe source code has to be readable in order to be compiled andinterpreted. (That doesn't mean that a \s-1CGI\s0 script's source isreadable by people on the web, though\*(--only by people with access tothe filesystem.) So you have to leave the permissions at the sociallyfriendly 0755 level..PPSome people regard this as a security problem. If your program doesinsecure things and relies on people not knowing how to exploit thoseinsecurities, it is not secure. It is often possible for someone todetermine the insecure things and exploit them without viewing thesource. Security through obscurity, the name for hiding your bugsinstead of fixing them, is little security indeed..PPYou can try using encryption via source filters (Starting from Perl5.8 the Filter::Simple and Filter::Util::Call modules are included inthe standard distribution), but any decent programmer will be able todecrypt it. You can try using the byte code compiler and interpreterdescribed later in perlfaq3, but the curious might still be able tode-compile it. You can try using the native-code compiler describedlater, but crackers might be able to disassemble it. These posevarying degrees of difficulty to people wanting to get at your code,but none can definitively conceal it (true of every language, not justPerl)..PPIt is very easy to recover the source of Perl programs. You simplyfeed the program to the perl interpreter and use the modules inthe B:: hierarchy. The B::Deparse module should be able todefeat most attempts to hide source. Again, this is notunique to Perl..PPIf you're concerned about people profiting from your code, then thebottom line is that nothing but a restrictive license will give youlegal security. License your software and pepper it with threateningstatements like \*(L"This is unpublished proprietary software of \s-1XYZ\s0 Corp.Your access to it does not give you permission to use it blah blahblah.\*(R" We are not lawyers, of course, so you should see a lawyer ifyou want to be sure your license's wording will stand up in court..Sh "How can I compile my Perl program into byte code or C?".IX Subsection "How can I compile my Perl program into byte code or C?"(contributed by brian d foy).PPIn general, you can't do this. There are some things that may workfor your situation though. People usually ask this questionbecause they want to distribute their works without giving awaythe source code, and most solutions trade disk space for convenience.You probably won't see much of a speed increase either, since mostsolutions simply bundle a Perl interpreter in the final product(but see \*(L"How can I make my Perl program run faster?\*(R")..PPThe Perl Archive Toolkit ( http://par.perl.org/ ) is Perl'sanalog to Java's \s-1JAR\s0. It's freely available and on \s-1CPAN\s0 (http://search.cpan.org/dist/PAR/ )..PPThere are also some commercial products that may work for you, althoughyou have to buy a license for them..PPThe Perl Dev Kit ( http://www.activestate.com/Products/Perl_Dev_Kit/ )from ActiveState can \*(L"Turn your Perl programs into ready-to-runexecutables for HP-UX, Linux, Solaris and Windows.\*(R".PPPerl2Exe ( http://www.indigostar.com/perl2exe.htm ) is a command lineprogram for converting perl scripts to executable files. It targets bothWindows and unix platforms..ie n .Sh "How can I get ""#!perl"" to work on [\s-1MS\-DOS\s0,NT,...]?".el .Sh "How can I get \f(CW#!perl\fP to work on [\s-1MS\-DOS\s0,NT,...]?".IX Subsection "How can I get #!perl to work on [MS-DOS,NT,...]?"For \s-1OS/2\s0 just use.PP.Vb 1\& extproc perl \-S \-your_switches.Ve.PPas the first line in \f(CW\*(C`*.cmd\*(C'\fR file (\f(CW\*(C`\-S\*(C'\fR due to a bug in cmd.exe's\&\*(L"extproc\*(R" handling). For \s-1DOS\s0 one should first invent a correspondingbatch file and codify it in \f(CW\*(C`ALTERNATE_SHEBANG\*(C'\fR (see the\&\fIdosish.h\fR file in the source distribution for more information)..PPThe Win95/NT installation, when using the ActiveState port of Perl,will modify the Registry to associate the \f(CW\*(C`.pl\*(C'\fR extension with theperl interpreter. If you install another port, perhaps even buildingyour own Win95/NT Perl from the standard sources by using a Windows portof gcc (e.g., with cygwin or mingw32), then you'll have to modifythe Registry yourself. In addition to associating \f(CW\*(C`.pl\*(C'\fR with theinterpreter, \s-1NT\s0 people can use: \f(CW\*(C`SET PATHEXT=%PATHEXT%;.PL\*(C'\fR to let themrun the program \f(CW\*(C`install\-linux.pl\*(C'\fR merely by typing \f(CW\*(C`install\-linux\*(C'\fR..PPUnder \*(L"Classic\*(R" MacOS, a perl program will have the appropriate Creator andType, so that double-clicking them will invoke the MacPerl application.Under Mac \s-1OS\s0 X, clickable apps can be made from any \f(CW\*(C`#!\*(C'\fR script using WilSanchez' DropScript utility: http://www.wsanchez.net/software/ ..PP\&\fI\s-1IMPORTANT\s0!\fR: Whatever you do, \s-1PLEASE\s0 don't get frustrated, and justthrow the perl interpreter into your cgi-bin directory, in order toget your programs working for a web server. This is an \s-1EXTREMELY\s0 bigsecurity risk. Take the time to figure out how to do it correctly..Sh "Can I write useful Perl programs on the command line?".IX Subsection "Can I write useful Perl programs on the command line?"Yes. Read perlrun for more information. Some examples follow.(These assume standard Unix shell quoting rules.).PP.Vb 2\& # sum first and last fields\& perl \-lane \*(Aqprint $F[0] + $F[\-1]\*(Aq *\&\& # identify text files\& perl \-le \*(Aqfor(@ARGV) {print if \-f && \-T _}\*(Aq *\&\& # remove (most) comments from C program\& perl \-0777 \-pe \*(Aqs{/\e*.*?\e*/}{}gs\*(Aq foo.c\&\& # make file a month younger than today, defeating reaper daemons\& perl \-e \*(Aq$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)\*(Aq *\&\& # find first unused uid\& perl \-le \*(Aq$i++ while getpwuid($i); print $i\*(Aq\&\& # display reasonable manpath\& echo $PATH | perl \-nl \-072 \-e \*(Aq\& s![^/+]*$!man!&&\-d&&!$s{$_}++&&push@m,$_;END{print"@m"}\*(Aq.Ve.PP\&\s-1OK\s0, the last one was actually an Obfuscated Perl Contest entry. :\-).Sh "Why don't Perl one-liners work on my DOS/Mac/VMS system?".IX Subsection "Why don't Perl one-liners work on my DOS/Mac/VMS system?"The problem is usually that the command interpreters on those systemshave rather different ideas about quoting than the Unix shells underwhich the one-liners were created. On some systems, you may have tochange single-quotes to double ones, which you must \fI\s-1NOT\s0\fR do on Unixor Plan9 systems. You might also have to change a single % to a %%..PPFor example:.PP.Vb 2\& # Unix (including Mac OS X)\& perl \-e \*(Aqprint "Hello world\en"\*(Aq\&\& # DOS, etc.\& perl \-e "print \e"Hello world\en\e""\&\& # Mac Classic\& print "Hello world\en"\& (then Run "Myscript" or Shift\-Command\-R)\&\& # MPW\& perl \-e \*(Aqprint "Hello world\en"\*(Aq\&\& # VMS\& perl \-e "print ""Hello world\en""".Ve.PPThe problem is that none of these examples are reliable: they depend on thecommand interpreter. Under Unix, the first two often work. Under \s-1DOS\s0,it's entirely possible that neither works. If 4DOS was the command shell,you'd probably have better luck like this:.PP.Vb 1\& perl \-e "print <Ctrl\-x>"Hello world\en<Ctrl\-x>"".Ve.PPUnder the Mac, it depends which environment you are using. The MacPerlshell, or \s-1MPW\s0, is much like Unix shells in its support for severalquoting variants, except that it makes free use of the Mac's non-ASCIIcharacters as control characters..PPUsing \fIqq()\fR, q(), and \fIqx()\fR, instead of \*(L"double quotes\*(R", 'singlequotes', and `backticks`, may make one-liners easier to write..PPThere is no general solution to all of this. It is a mess..PP[Some of this answer was contributed by Kenneth Albanowski.].Sh "Where can I learn about \s-1CGI\s0 or Web programming in Perl?".IX Subsection "Where can I learn about CGI or Web programming in Perl?"For modules, get the \s-1CGI\s0 or \s-1LWP\s0 modules from \s-1CPAN\s0. For textbooks,see the two especially dedicated to web stuff in the question onbooks. For problems and questions related to the web, like \*(L"Whydo I get 500 Errors\*(R" or \*(L"Why doesn't it run from the browser rightwhen it runs fine on the command line\*(R", see the troubleshootingguides and references in perlfaq9 or in the \s-1CGI\s0 MetaFAQ:.PP.Vb 1\& http://www.perl.org/CGI_MetaFAQ.html.Ve.Sh "Where can I learn about object-oriented Perl programming?".IX Subsection "Where can I learn about object-oriented Perl programming?"A good place to start is perltoot, and you can use perlobj,perlboot, perltoot, perltooc, and perlbot for reference..PPA good book on \s-1OO\s0 on Perl is the \*(L"Object-Oriented Perl\*(R"by Damian Conway from Manning Publications, or \*(L"Intermediate Perl\*(R"by Randal Schwartz, brian d foy, and Tom Phoenix from O'Reilly Media..Sh "Where can I learn about linking C with Perl?".IX Subsection "Where can I learn about linking C with Perl?"If you want to call C from Perl, start with perlxstut,moving on to perlxs, xsubpp, and perlguts. If you want tocall Perl from C, then read perlembed, perlcall, andperlguts. Don't forget that you can learn a lot from looking athow the authors of existing extension modules wrote their code andsolved their problems..PPYou might not need all the power of \s-1XS\s0. The Inline::C module letsyou put C code directly in your Perl source. It handles all themagic to make it work. You still have to learn at least some ofthe perl \s-1API\s0 but you won't have to deal with the complexity of the\&\s-1XS\s0 support files..Sh "I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong?".IX Subsection "I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong?"Download the ExtUtils::Embed kit from \s-1CPAN\s0 and run `make test'. Ifthe tests pass, read the pods again and again and again. If theyfail, see perlbug and send a bug report with the output of\&\f(CW\*(C`make test TEST_VERBOSE=1\*(C'\fR along with \f(CW\*(C`perl \-V\*(C'\fR..Sh "When I tried to run my script, I got this message. What does it mean?".IX Subsection "When I tried to run my script, I got this message. What does it mean?"A complete list of Perl's error messages and warnings with explanatorytext can be found in perldiag. You can also use the splain program(distributed with Perl) to explain the error messages:.PP.Vb 2\& perl program 2>diag.out\& splain [\-v] [\-p] diag.out.Ve.PPor change your program to explain the messages for you:.PP.Vb 1\& use diagnostics;.Ve.PPor.PP.Vb 1\& use diagnostics \-verbose;.Ve.Sh "What's MakeMaker?".IX Subsection "What's MakeMaker?"(contributed by brian d foy).PPThe \f(CW\*(C`ExtUtils::MakeMaker\*(C'\fR module, better known simply as \*(L"MakeMaker\*(R",turns a Perl script, typically called \f(CW\*(C`Makefile.PL\*(C'\fR, into a Makefile.The unix tool \f(CW\*(C`make\*(C'\fR uses this file to manage dependencies and actionsto process and install a Perl distribution..SH "REVISION".IX Header "REVISION"Revision: \f(CW$Revision:\fR 10127 $.PPDate: \f(CW$Date:\fR 2007\-10\-27 21:40:20 +0200 (Sat, 27 Oct 2007) $.PPSee perlfaq for source control details and availability..SH "AUTHOR AND COPYRIGHT".IX Header "AUTHOR AND COPYRIGHT"Copyright (c) 1997\-2007 Tom Christiansen, Nathan Torkington, andother authors as noted. All rights reserved..PPThis documentation is free; you can redistribute it and/or modify itunder the same terms as Perl itself..PPIrrespective of its distribution, all code examples here are in the publicdomain. You are permitted and encouraged to use this code and anyderivatives thereof in your own programs for fun or for profit as yousee fit. A simple comment in the code giving credit to the \s-1FAQ\s0 wouldbe courteous but is not required.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -