PerlFAQ sync.
[p5sagit/p5-mst-13.2.git] / pod / perlfaq3.pod
index 0f678f1..7843dbf 100644 (file)
@@ -1,6 +1,6 @@
 =head1 NAME
 
-perlfaq3 - Programming Tools ($Revision: 1.15 $, $Date: 2002/02/11 19:29:52 $)
+perlfaq3 - Programming Tools ($Revision: 1.31 $, $Date: 2003/01/03 20:10:11 $)
 
 =head1 DESCRIPTION
 
@@ -59,9 +59,53 @@ which aren't part of the Perl language as shell commands.  perlsh
 from the source distribution is simplistic and uninteresting, but
 may still be 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
+installed distributions, although it can take awhile to do
+its magic.  The standard library which comes with Perl just
+shows up as "Perl" (although you can get those with
+Mod::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, you
+can 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 thing
+with File::Find which is part of the standard library.
+
+    use File::Find;
+    my @files;
+
+    find sub { push @files, $File::Find::name if -f _ && /\.pm$/ },
+         @INC;
+
+       print join "\n", @files;
+
+If you simply need to quickly check to see if a module is
+available, you can check for its documentation.  If you can
+read the documentation the module is most likely installed.
+If you cannot read the documentation, the module might not
+have any (in rare cases).
+
+       prompt% perldoc Module::Name
+
+You can also try to include the module in a one-liner to see if
+perl finds it.
+
+       perl -MModule::Name -e1
+
 =head2 How do I debug my Perl programs?
 
-Have you tried C<use warnings> or used C<-w>?  They enable warnings 
+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 symbolic
@@ -87,9 +131,9 @@ why 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 
+(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:
@@ -123,7 +167,7 @@ of contrasting algorithms.
 
 =head2 How do I cross-reference my Perl programs?
 
-The B::Xref module can be used to generate cross-reference reports 
+The B::Xref module can be used to generate cross-reference reports
 for Perl programs.
 
     perl -MO=Xref[,OPTIONS] scriptname.plx
@@ -154,9 +198,9 @@ for indenting, ^D is for undenting, and ^O is for blockdenting--
 as it were.  A more complete example, with comments, can be found at
 http://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gz
 
-The a2ps http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps does
+The a2ps http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz does
 lots of things related to generating nicely printed output of
-documents, as does enscript at http://people.ssh.fi/mtr/genscript/.
+documents, as does enscript at http://people.ssh.fi/mtr/genscript/ .
 
 =head2 Is there a ctags for Perl?
 
@@ -185,13 +229,13 @@ If you want an IDE, check the following:
 ActiveState's cross-platform (as of April 2001 Windows and Linux),
 multi-language IDE has Perl support, including a regular expression
 debugger and remote debugging
-(http://www.ActiveState.com/Products/Komodo/index.html).  (Visual
+( 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)).
+( http://www.ActiveState.com/Products/VisualPerl/index.html )).
 
 =item The Object System
 
-(http://www.castlelink.co.uk/object_system/) is a Perl web
+( http://www.castlelink.co.uk/object_system/ ) is a Perl web
 applications development IDE, apparently for any platform
 that runs Perl.
 
@@ -204,7 +248,7 @@ under Windows 95/98/NT/2000.
 
 =item PerlBuilder
 
-(http://www.solutionsoft.com/perl.htm) is an integrated development
+( http://www.solutionsoft.com/perl.htm ) is an integrated development
 environment for Windows that supports Perl development.
 
 =item visiPerl+
@@ -212,18 +256,10 @@ environment for Windows that supports Perl development.
 ( http://helpconsulting.net/visiperl/ )
 From Help Consulting, for Windows.
 
-=back
-
-For Windows there's also the
-
-=over 4
-
-=item CodeMagicCD
+=item OptiPerl
 
-( http://www.codemagiccd.com/ ) Collection of various programming
-tools for Windows: Perl (5.005_03), TclTk, Python, GNU programming
-tools, REBOL, wxWindows toolkit, the MinGW GNU C/C++ compiler, DJGPP
-GNU C/C++ compiler, Cint C interpreter, YaBasic.
+( http://www.optiperl.com/ ) is a Windows IDE with simulated CGI
+environment, including debugger and syntax highlighting editor.
 
 =back
 
@@ -239,14 +275,14 @@ do not work since they insert all sorts of behind-the-scenes
 information, although some allow you to save files as "Text
 Only". You can also download text editors designed
 specifically for programming, such as Textpad
-(http://www.textpad.com/) and UltraEdit
-(http://www.ultraedit.com), among others.
+( http://www.textpad.com/ ) and UltraEdit
+( http://www.ultraedit.com/ ), among others.
 
 If you are using MacOS, the same concerns apply.  MacPerl
 (for Classic environments) comes with a simple editor.
-Popular external editors are BBEdit (http://www.bbedit.com)
-or Alpha (http://alpha.olm.net/). MacOS X users can use Unix
-editors as well.
+Popular external editors are BBEdit ( http://www.bbedit.com/ )
+or Alpha ( http://www.kelehers.org/alpha/ ). MacOS X users can
+use Unix editors as well.
 
 =over 4
 
@@ -256,12 +292,16 @@ http://www.gnu.org/software/emacs/windows/ntemacs.html
 
 =item MicroEMACS
 
-http://members.nbci.com/uemacs/
+http://www.microemacs.de/
 
 =item XEmacs
 
 http://www.xemacs.org/Download/index.html
 
+=item Jed
+
+http://space.mit.edu/~davis/jed/
+
 =back
 
 or a vi clone such as
@@ -274,20 +314,19 @@ ftp://ftp.cs.pdx.edu/pub/elvis/ http://www.fh-wedel.de/elvis/
 
 =item Vile
 
-http://vile.cx/
+http://dickey.his.com/vile/vile.html
 
 =item Vim
 
 http://www.vim.org/
 
-win32: http://www.cs.vu.nl/%7Etmgil/vi.html
-
 =back
 
 For 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/) is
+       http://www.thomer.com/thomer/vi/vi.html
+
+nvi ( http://www.bostic.com/vi/ , available from CPAN in src/misc/) is
 yet another vi clone, unfortunately not available for Windows, but in
 UNIX platforms you might be interested in trying it out, firstly because
 strictly speaking it is not a vi clone, it is the real vi, or the new
@@ -315,9 +354,9 @@ http://www.slickedit.com/
 
 There is also a toyedit Text widget based editor written in Perl
 that is distributed with the Tk module on CPAN.  The ptkdb
-(http://world.std.com/~aep/ptkdb/) is a Perl/tk based debugger that
+( http://world.std.com/~aep/ptkdb/ ) is a Perl/tk based debugger that
 acts as a development environment of sorts.  Perl Composer
-(http://perlcomposer.sourceforge.net/vperl.html) is an IDE for Perl/Tk
+( http://perlcomposer.sourceforge.net/ ) is an IDE for Perl/Tk
 GUI creation.
 
 In addition to an editor/IDE you might be interested in a more
@@ -327,21 +366,21 @@ powerful shell environment for Win32.  Your options include
 
 =item Bash
 
-from the Cygwin package (http://sources.redhat.com/cygwin/)
+from the Cygwin package ( http://sources.redhat.com/cygwin/ )
 
 =item Ksh
 
-from the MKS Toolkit (http://www.mks.com/), or the Bourne shell of
-the U/WIN environment (http://www.research.att.com/sw/tools/uwin/)
+from the MKS Toolkit ( http://www.mks.com/ ), or the Bourne shell of
+the U/WIN environment ( http://www.research.att.com/sw/tools/uwin/ )
 
 =item Tcsh
 
-ftp://ftp.astron.com/pub/tcsh/, see also
+ftp://ftp.astron.com/pub/tcsh/ , see also
 http://www.primate.wisc.edu/software/csh-tcsh-book/
 
 =item Zsh
 
-ftp://ftp.blarg.net/users/amol/zsh/, see also http://www.zsh.org/
+ftp://ftp.blarg.net/users/amol/zsh/ , see also http://www.zsh.org/
 
 =back
 
@@ -365,18 +404,18 @@ no 32k limit).
 =item BBEdit and BBEdit Lite
 
 are text editors for Mac OS that have a Perl sensitivity mode
-(http://web.barebones.com/).
+( http://web.barebones.com/ ).
 
 =item Alpha
 
 is an editor, written and extensible in Tcl, that nonetheless has
 built in support for several popular markup and programming languages
-including Perl and HTML (http://alpha.olm.net/).
+including Perl and HTML ( http://alpha.olm.net/ ).
 
 =back
 
 Pepper and Pe are programming language sensitive text editors for Mac
-OS X and BeOS respectively (http://www.hekkelman.com/).
+OS X and BeOS respectively ( http://www.hekkelman.com/ ).
 
 =head2 Where can I get Perl macros for vi?
 
@@ -384,7 +423,7 @@ For a complete version of Tom Christiansen's vi configuration file,
 see http://www.cpan.org/authors/Tom_Christiansen/scripts/toms.exrc.gz ,
 the standard benchmark file for vi emulators.  The file 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.cpan.org/src/misc.
+with an embedded Perl interpreter--see http://www.cpan.org/src/misc/ .
 
 =head2 Where can I get perl-mode for emacs?
 
@@ -405,7 +444,7 @@ shouldn't be an issue.
 
 The Curses module from CPAN provides a dynamically loadable object
 module interface to a curses library.  A small demo can be found at the
-directory http://www.cpan.org/authors/Tom_Christiansen/scripts/rep;
+directory http://www.cpan.org/authors/Tom_Christiansen/scripts/rep.gz ;
 this program repeats a command and updates the screen as needed, rendering
 B<rep ps axu> similar to B<top>.
 
@@ -527,7 +566,7 @@ instead of this:
 
 When the files you're processing are small, it doesn't much matter which
 way you do it, but it makes a huge difference when they start getting
-larger. 
+larger.
 
 =item * Use map and grep selectively
 
@@ -587,21 +626,22 @@ copy, you'll have to sacrifice the memory needed to make one.
 
 For "big" data stores (i.e. ones that exceed available memory) consider
 using one of the DB modules to store it on disk instead of in RAM. This
-will incur a penalty in access time, but that's probably better that
+will incur a penalty in access time, but that's probably better than
 causing your hard disk to thrash due to massive swapping.
 
 =back
 
-=head2 Is it unsafe to return a pointer to local data?
+=head2 Is it safe to return a reference to local or lexical data?
 
-No, Perl's garbage collection system takes care of this.
+Yes. Perl's garbage collection system takes care of this so
+everything works out right.
 
     sub makeone {
        my @a = ( 1 .. 10 );
        return \@a;
     }
 
-    for $i ( 1 .. 10 ) {
+    for ( 1 .. 10 ) {
         push @many, makeone();
     }
 
@@ -611,17 +651,14 @@ 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.  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 and Linux) 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.
-
-We've had reports that on Linux (Redhat 5.1) on Intel, C<undef
-$scalar> will return memory to the system, while on Solaris 2.6 it
-won't.  In general, try it yourself and see.
+You usually 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, systems that
+use mmap(2) for allocating large chunks of memory) can
+reclaim memory that is no longer used, but on such systems,
+perl must be configured and compiled to use the OS's malloc,
+not perl's.
 
 However, judicious use of my() on your variables will help make sure
 that they go out of scope so that Perl can free up that space for
@@ -643,7 +680,7 @@ you> because the process start-up overhead is where the bottleneck is.
 
 There are two popular ways to avoid this overhead.  One solution
 involves running the Apache HTTP server (available from
-http://www.apache.org/) with either of the mod_perl or mod_fastcgi
+http://www.apache.org/ ) with either of the mod_perl or mod_fastcgi
 plugin modules.
 
 With mod_perl and the Apache::Registry module (distributed with
@@ -655,7 +692,7 @@ anything a module written in C can.  For more on mod_perl, see
 http://perl.apache.org/
 
 With the FCGI module (from CPAN) and the mod_fastcgi
-module (available from http://www.fastcgi.com/) each of your Perl
+module (available from http://www.fastcgi.com/ ) each of your Perl
 programs becomes a permanent CGI daemon process.
 
 Both of these solutions can have far-reaching effects on your system
@@ -702,6 +739,12 @@ 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 (true of every language, not just Perl).
 
+It is very easy to recover the source of Perl programs.  You simply
+feed the program to the perl interpreter and use the modules in
+the B:: hierarchy.  The B::Deparse module should be able to
+defeat most attempts to hide source.  Again, this is not
+unique to Perl.
+
 If you're concerned about people profiting from your code, then the
 bottom line is that nothing but a restrictive license will give you
 legal security.  License your software and pepper it with threatening
@@ -876,7 +919,7 @@ L<perlboot>, L<perltoot>, L<perltooc>, and L<perlbot> for reference.
 try http://www.perldoc.com/ , but consider upgrading your perl.)
 
 A good book on OO on Perl is the "Object-Oriented Perl"
-by Damian Conway from Manning Publications, 
+by Damian Conway from Manning Publications,
 http://www.manning.com/Conway/index.html
 
 =head2 Where can I learn about linking C with Perl? [h2xs, xsubpp]