This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
applied patch, add new message to perldeta
[perl5.git] / pod / perlfaq3.pod
index 121743d..62073e8 100644 (file)
@@ -1,6 +1,6 @@
 =head1 NAME
 
-perlfaq3 - Programming Tools ($Revision: 1.19 $)
+perlfaq3 - Programming Tools ($Revision: 1.27 $, $Date: 1998/07/05 15:07:20 $)
 
 =head1 DESCRIPTION
 
@@ -13,10 +13,13 @@ Have you looked at CPAN (see L<perlfaq2>)?  The chances are that
 someone 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, perlsub
-       Regexps         perlre, perlfunc, perlop
+       Modules         perlmod, perlmodlib, perlsub
+       Regexps         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
@@ -65,10 +68,10 @@ breakdowns of where your code spends its time.
 =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), can be used to generate
-cross-reference reports for Perl programs.
+(not the general distribution prior to the 5.005 release), can be used
+to generate cross-reference reports for Perl programs.
 
-    perl -MO=Xref[,OPTIONS] foo.pl
+    perl -MO=Xref[,OPTIONS] scriptname.plx
 
 =head2 Is there a pretty-printer (formatter) for Perl?
 
@@ -85,7 +88,7 @@ perl-mode for emacs can provide a remarkable amount of help with most
 (but not all) code, and even less programmable editors can provide
 significant assistance.
 
-If you are using to using vgrind program for printing out nice code to
+If you are used to using vgrind program for printing out nice code to
 a laser printer, you can take a stab at this using
 http://www.perl.com/CPAN/doc/misc/tips/working.vgrind.entry, but the
 results are not particularly satisfying for sophisticated code.
@@ -99,10 +102,10 @@ the trick.
 =head2 Where can I get Perl macros for vi?
 
 For a complete version of Tom Christiansen's vi configuration file,
-see ftp://ftp.perl.com/pub/vi/toms.exrc, the standard benchmark file
-for vi emulators.  This runs best with nvi, the current version of vi
-out of Berkeley, which incidentally can be built with an embedded Perl
-interpreter -- see http://www.perl.com/CPAN/src/misc .
+see http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/toms.exrc,
+the standard benchmark file for vi emulators.  This runs best with nvi,
+the current version of vi out of Berkeley, which incidentally can be built
+with an embedded Perl interpreter -- see http://www.perl.com/CPAN/src/misc.
 
 =head2 Where can I get perl-mode for emacs?
 
@@ -121,25 +124,23 @@ should be using "main::foo", anyway.
 =head2 How can I use curses with Perl?
 
 The Curses module from CPAN provides a dynamically loadable object
-module interface to a curses library.
+module interface to a curses library.  A small demo can be found at the
+directory http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/rep;
+this program repeats a command and updates the screen as needed, rendering
+B<rep ps axu> similar to B<top>.
 
 =head2 How can I use X or Tk with Perl?
 
-Tk is a completely Perl-based, object-oriented interface to the Tk
-toolkit that doesn't force you to use Tcl just to get at Tk.  Sx is an
-interface to the Athena Widget set.  Both are available from CPAN.
+Tk is a completely Perl-based, object-oriented interface to the Tk toolkit
+that doesn't force you to use Tcl just to get at Tk.  Sx is an interface
+to the Athena Widget set.  Both are available from CPAN.  See the
+directory http://www.perl.com/CPAN/modules/by-category/08_User_Interfaces/
 
 =head2 How can I generate simple menus without using CGI or Tk?
 
 The http://www.perl.com/CPAN/authors/id/SKUNZ/perlmenu.v4.0.tar.gz
 module, which is curses-based, can help with this.
 
-=head2 Can I dynamically load C routines into Perl?
-
-If your system architecture supports it, then the standard perl
-on your system should also provide you with this via the
-DynaLoader module.  Read L<perlxstut> for details.
-
 =head2 What is undump?
 
 See the next questions.
@@ -200,7 +201,7 @@ structure.  If you're working with specialist data structures
 less memory than equivalent Perl modules.
 
 Another thing to try is learning whether your Perl was compiled with
-the system malloc or with Perl's built-in malloc.  Whichever one it
+the system malloc or with Perl's builtin malloc.  Whichever one it
 is, try using the other one and see whether this makes a difference.
 Information about malloc is in the F<INSTALL> file in the source
 distribution.  You can find out whether you are using perl's malloc by
@@ -225,9 +226,12 @@ No, Perl's garbage collection system takes care of this.
 
 =head2 How can I free an array or hash so my program shrinks?
 
-You can't.  Memory the system allocates to a program will never be
-returned to the system.  That's why long-running programs sometimes
-re-exec themselves.
+You can't.  On most operating systems, memory allocated to a program
+can never be returned to the system.  That's why long-running programs
+sometimes re-exec themselves.  Some operating systems (notably, FreeBSD)
+allegedly reclaim large chunks of memory that is no longer used, but
+it doesn't appear to happen with Perl (yet).  The Mac appears to be the
+only platform that will reliably (albeit, slowly) return memory to the OS.
 
 However, judicious use of my() on your variables will help make sure
 that they go out of scope so that Perl can free up their storage for
@@ -260,12 +264,22 @@ module written in C can.  With the FCGI module (from CPAN), a Perl
 executable compiled with sfio (see the F<INSTALL> file in the
 distribution) and the mod_fastcgi module (available from
 http://www.fastcgi.com/) each of your perl scripts becomes a permanent
-CGI daemon processes.
+CGI daemon process.
 
 Both of these solutions can have far-reaching effects on your system
 and on the way you write your CGI scripts, so investigate them with
 care.
 
+See http://www.perl.com/CPAN/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/.
+
+A non-free, commerical product, 'The Velocity Engine for Perl',
+(http://www.binevolve.com/ or http://www.binevolve.com/bine/vep) might
+also be worth looking at.  It will allow you to increase the performance
+of your perl scripts, upto 25 times faster than normal cgi perl by
+running in persistent perl mode, or 4 to 5 times faster without any
+modification to your existing cgi scripts. Fully functional evaluation
+copies are available from the web site.
+
 =head2 How can I hide the source for my Perl program?
 
 Delete it. :-) Seriously, there are a number of (mostly
@@ -285,9 +299,9 @@ source.  Security through obscurity, the name for hiding your bugs
 instead of fixing them, is little security indeed.
 
 You can try using encryption via source filters (Filter::* from CPAN).
-But crackers might be able to decrypt it.  You can try using the
-byte-code compiler and interpreter described below, but crackers might
-be able to de-compile it.  You can try using the native-code compiler
+But crackers might be able to decrypt it.  You can try using the byte
+code compiler and interpreter described below, but crackers might be
+able to de-compile it.  You can try using the native-code compiler
 described below, but crackers might be able to disassemble it.  These
 pose varying degrees of difficulty to people wanting to get at your
 code, but none can definitively conceal it (this is true of every
@@ -301,7 +315,7 @@ Your access to it does not give you permission to use it blah blah
 blah."  We are not lawyers, of course, so you should see a lawyer if
 you want to be sure your licence's wording will stand up in court.
 
-=head2 How can I compile my Perl program into byte-code or C?
+=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 as of
@@ -319,9 +333,10 @@ save little more than compilation time, leaving execution no more than
 (like several times faster), but this takes some tweaking of your
 code.
 
-Malcolm will be in charge of the 5.005 release of Perl itself
-to try to unify and merge his compiler and multithreading work into
-the main release.
+The 5.005 release of Perl itself, whose main goal is merging the various
+non-Unix ports back into the one Perl source, will also have preliminary
+(strictly beta) support for Malcolm's compiler and his light-weight
+processes (sometimes called "threads").
 
 You'll probably be astonished to learn that the current version of the
 compiler generates a compiled form of your script whose executable is
@@ -334,7 +349,17 @@ you link your main perl binary with this, it will make it miniscule.
 For example, on one author's system, /usr/bin/perl is only 11k in
 size!
 
-=head2 How can I get '#!perl' to work on [MSDOS,NT,...]?
+In general, the compiler will do nothing to make a Perl program smaller,
+faster, more portable, or more secure.  In fact, it will usually hurt
+all of those.  The executable will be bigger, your VM system may take
+longer 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 merely
+packaging, and once you see the size of what it makes (well, unless
+you use a shared I<libperl.so>), you'll probably want a complete
+Perl install anywayt.
+
+=head2 How can I get '#!perl' to work on [MS-DOS,NT,...]?
 
 For OS/2 just use
 
@@ -365,12 +390,12 @@ 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]'
+    perl -lane 'print $F[0] + $F[-1]' *
 
     # identify text files
     perl -le 'for(@ARGV) {print if -f && -T _}' *
 
-    # remove comments from C program
+    # remove (most) comments from C program
     perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c
 
     # make file a month younger than today, defeating reaper daemons
@@ -433,21 +458,28 @@ books.  For problems and questions related to the web, like "Why
 do I get 500 Errors" or "Why doesn't it run from the browser right
 when it runs fine on the command line", see these sources:
 
-    The Idiot's Guide to Solving Perl/CGI Problems, by Tom Christiansen
-       http://www.perl.com/perl/faq/idiots-guide.html
+    WWW Security FAQ
+        http://www.w3.org/Security/Faq/
 
-    Frequently Asked Questions about CGI Programming, by Nick Kew
-       ftp://rtfm.mit.edu/pub/usenet/news.answers/www/cgi-faq
-       http://www3.pair.com/webthing/docs/cgi/faqs/cgifaq.shtml
+    Web FAQ
+        http://www.boutell.com/faq/
 
-    Perl/CGI programming FAQ, by Shishir Gundavaram and Tom Christiansen
-       http://www.perl.com/perl/faq/perl-cgi-faq.html
+    CGI FAQ
+        http://www.webthing.com/page.cgi/cgifaq
 
-    The WWW Security FAQ, by Lincoln Stein
-       http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.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
 
-    World Wide Web FAQ, by Thomas Boutell
-       http://www.boutell.com/faq/
 
 =head2 Where can I learn about object-oriented Perl programming?
 
@@ -470,7 +502,7 @@ my C program, what am I doing wrong?
 
 Download the ExtUtils::Embed kit from CPAN and run `make test'.  If
 the tests pass, read the pods again and again and again.  If they
-fail, see L<perlbug> and send a bugreport with the output of 
+fail, see L<perlbug> and send a bugreport with the output of
 C<make test TEST_VERBOSE=1> along with C<perl -V>.
 
 =head2 When I tried to run my script, I got this message. What does it
@@ -499,5 +531,16 @@ information, see L<ExtUtils::MakeMaker>.
 
 =head1 AUTHOR AND COPYRIGHT
 
-Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
-All rights reserved.  See L<perlfaq> for distribution information.
+Copyright (c) 1997, 1998 Tom Christiansen and Nathan Torkington.
+All rights reserved.
+
+When included as an integrated part of the Standard Distribution
+of Perl or of its documentation (printed or otherwise), this works is
+covered under Perl's Artistic Licence.  For separate distributions of
+all or part of this FAQ outside of that, see L<perlfaq>.
+
+Irrespective of its distribution, all code examples here are public
+domain.  You are permitted and encouraged to use this code and any
+derivatives thereof in your own programs for fun or for profit as you
+see fit.  A simple comment in the code giving credit to the FAQ would
+be courteous but is not required.