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

📄 perlfaq.pod

📁 source of perl for linux application,
💻 POD
📖 第 1 页 / 共 3 页
字号:
First of all, however, you I<can't> take away read permission, becausethe source code has to be readable in order to be compiled andinterpreted.  (That doesn't mean that a CGI 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.Some 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.You can try using encryption via source filters (Filter::* from CPAN),but any decent programmer will be able to decrypt it.  You can try usingthe byte code compiler and interpreter described below, but the curiousmight still be able to de-compile it.  You can try using the native-codecompiler described below, but crackers might be able to disassemble it.These pose varying degrees of difficulty to people wanting to get atyour code, but none can definitively conceal it (true of everylanguage, not just Perl).If 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 ``This is unpublished proprietary software of XYZ Corp.Your access to it does not give you permission to use it blah blahblah.''  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.=head2 How can I compile my Perl program into byte code or C?Malcolm Beattie has written a multifunction backend compiler,available from CPAN, that can do both these things.  It is includedin the perl5.005 release, but is still considered experimental.This means it's fun to play with if you're a programmer but notreally for people looking for turn-key solutions.Merely compiling into C does not in and of itself guarantee that yourcode will run very much faster.  That's because except for lucky caseswhere a lot of native type inferencing is possible, the normal Perlrun-time system is still present and so your program will take just aslong to run and be just as big.  Most programs save little more thancompilation time, leaving execution no more than 10-30% faster.  A fewrare programs actually benefit significantly (even running several timesfaster), but this takes some tweaking of your code.You'll probably be astonished to learn that the current version of thecompiler generates a compiled form of your script whose executable isjust as big as the original perl executable, and then some.  That'sbecause as currently written, all programs are prepared for a fulleval() statement.  You can tremendously reduce this cost by building ashared I<libperl.so> library and linking against that.  See theF<INSTALL> podfile in the Perl source distribution for details.  Ifyou link your main perl binary with this, it will make it minuscule.For example, on one author's system, F</usr/bin/perl> is only 11k insize!In general, the compiler will do nothing to make a Perl program smaller,faster, more portable, or more secure.  In fact, it can make yoursituation worse.  The executable will be bigger, your VM system may takelonger to load the whole thing, the binary is fragile and hard to fix,and compilation never stopped software piracy in the form of crackers,viruses, or bootleggers.  The real advantage of the compiler is merelypackaging, and once you see the size of what it makes (well, unlessyou use a shared I<libperl.so>), you'll probably want a completePerl install anyway.=head2 How can I compile Perl into Java?You can also integrate Java and Perl with thePerl Resource Kit from O'Reilly and Associates.  Seehttp://www.oreilly.com/catalog/prkunix/ .Perl 5.6 comes with Java Perl Lingo, or JPL.  JPL, still indevelopment, allows Perl code to be called from Java.  See jpl/READMEin the Perl source tree.=head2 How can I get C<#!perl> to work on [MS-DOS,NT,...]?For OS/2 just use    extproc perl -S -your_switchesas the first line in C<*.cmd> file (C<-S> due to a bug in cmd.exe's`extproc' handling).  For DOS one should first invent a correspondingbatch file and codify it in C<ALTERNATIVE_SHEBANG> (see theF<INSTALL> file in the source distribution for more information).The Win95/NT installation, when using the ActiveState port of Perl,will modify the Registry to associate the C<.pl> 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 C<.pl> with theinterpreter, NT people can use: C<SET PATHEXT=%PATHEXT%;.PL> to let themrun the program C<install-linux.pl> merely by typing C<install-linux>.Macintosh Perl programs will have the appropriate Creator andType, so that double-clicking them will invoke the Perl application.I<IMPORTANT!>: Whatever you do, PLEASE 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 EXTREMELY bigsecurity risk.  Take the time to figure out how to do it correctly.=head2 Can I write useful Perl programs on the command line?Yes.  Read L<perlrun> for more information.  Some examples follow.(These assume standard Unix shell quoting rules.)    # sum first and last fields    perl -lane 'print $F[0] + $F[-1]' *    # identify text files    perl -le 'for(@ARGV) {print if -f && -T _}' *    # remove (most) comments from C program    perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c    # make file a month younger than today, defeating reaper daemons    perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' *    # find first unused uid    perl -le '$i++ while getpwuid($i); print $i'    # display reasonable manpath    echo $PATH | perl -nl -072 -e '	s![^/+]*$!man!&&-d&&!$s{$_}++&&push@m,$_;END{print"@m"}'OK, the last one was actually an Obfuscated Perl Contest entry. :-)=head2 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 I<NOT> do on Unixor Plan9 systems.  You might also have to change a single % to a %%.For example:    # Unix    perl -e 'print "Hello world\n"'    # DOS, etc.    perl -e "print \"Hello world\n\""    # Mac    print "Hello world\n"     (then Run "Myscript" or Shift-Command-R)    # VMS    perl -e "print ""Hello world\n"""The problem is that none of these examples are reliable: they depend on thecommand interpreter.  Under Unix, the first two often work. Under DOS,it's entirely possible that neither works.  If 4DOS was the command shell,you'd probably have better luck like this:  perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""Under the Mac, it depends which environment you are using.  The MacPerlshell, or MPW, 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.Using qq(), q(), and qx(), instead of "double quotes", 'singlequotes', and `backticks`, may make one-liners easier to write.There is no general solution to all of this.  It is a mess, pure andsimple.  Sucks to be away from Unix, huh? :-)[Some of this answer was contributed by Kenneth Albanowski.]=head2 Where can I learn about CGI or Web programming in Perl?For modules, get the CGI or LWP modules from CPAN.  For textbooks,see the two especially dedicated to web stuff in the question onbooks.  For problems and questions related to the web, like ``Whydo I get 500 Errors'' or ``Why doesn't it run from the browser rightwhen it runs fine on the command line'', see these sources:    WWW Security FAQ        http://www.w3.org/Security/Faq/    Web FAQ        http://www.boutell.com/faq/    CGI FAQ        http://www.webthing.com/tutorials/cgifaq.html    HTTP Spec        http://www.w3.org/pub/WWW/Protocols/HTTP/    HTML Spec        http://www.w3.org/TR/REC-html40/        http://www.w3.org/pub/WWW/MarkUp/    CGI Spec        http://www.w3.org/CGI/    CGI Security FAQ        http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt=head2 Where can I learn about object-oriented Perl programming?A good place to start is L<perltoot>, and you can use L<perlobj>,L<perlboot>, and L<perlbot> for reference.  Perltoot didn't come outuntil the 5.004 release; you can get a copy (in pod, html, orpostscript) from http://www.perl.com/CPAN/doc/FMTEYEWTK/ .=head2 Where can I learn about linking C with Perl? [h2xs, xsubpp]If you want to call C from Perl, start with L<perlxstut>,moving on to L<perlxs>, L<xsubpp>, and L<perlguts>.  If you want tocall Perl from C, then read L<perlembed>, L<perlcall>, andL<perlguts>.  Don't forget that you can learn a lot from looking athow the authors of existing extension modules wrote their code andsolved their problems.=head2 I've read perlembed, perlguts, etc., but I can't embed perl inmy C program; what am I doing wrong?Download the ExtUtils::Embed kit from CPAN and run `make test'.  Ifthe tests pass, read the pods again and again and again.  If theyfail, see L<perlbug> and send a bug report with the output ofC<make test TEST_VERBOSE=1> along with C<perl -V>.=head2 When I tried to run my script, I got this message. What does itmean?A complete list of Perl's error messages and warnings with explanatorytext can be found in L<perldiag>. You can also use the splain program(distributed with Perl) to explain the error messages:    perl program 2>diag.out    splain [-v] [-p] diag.outor change your program to explain the messages for you:    use diagnostics;or    use diagnostics -verbose;=head2 What's MakeMaker?This module (part of the standard Perl distribution) is designed towrite a Makefile for an extension module from a Makefile.PL.  For moreinformation, see L<ExtUtils::MakeMaker>.=head1 AUTHOR AND COPYRIGHTCopyright (c) 1997-1999 Tom Christiansen and Nathan Torkington.All rights reserved.When included as an integrated part of the Standard Distributionof Perl or of its documentation (printed or otherwise), this works iscovered under Perl's Artistic License.  For separate distributions ofall or part of this FAQ outside of that, see L<perlfaq>.Irrespective 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 FAQ wouldbe courteous but is not required.

⌨️ 快捷键说明

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