source: trunk/essentials/dev-lang/perl/pod/perlfaq3.pod@ 3280

Last change on this file since 3280 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 34.4 KB
Line 
1=head1 NAME
2
3perlfaq3 - Programming Tools ($Revision: 1.56 $, $Date: 2005/12/31 00:54:37 $)
4
5=head1 DESCRIPTION
6
7This section of the FAQ answers questions related to programmer tools
8and programming support.
9
10=head2 How do I do (anything)?
11
12Have you looked at CPAN (see L<perlfaq2>)? The chances are that
13someone has already written a module that can solve your problem.
14Have you read the appropriate manpages? Here's a brief index:
15
16 Basics perldata, perlvar, perlsyn, perlop, perlsub
17 Execution perlrun, perldebug
18 Functions perlfunc
19 Objects perlref, perlmod, perlobj, perltie
20 Data Structures perlref, perllol, perldsc
21 Modules perlmod, perlmodlib, perlsub
22 Regexes perlre, perlfunc, perlop, perllocale
23 Moving to perl5 perltrap, perl
24 Linking w/C perlxstut, perlxs, perlcall, perlguts, perlembed
25 Various http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz
26 (not a man-page but still useful, a collection
27 of various essays on Perl techniques)
28
29A crude table of contents for the Perl manpage set is found in L<perltoc>.
30
31=head2 How can I use Perl interactively?
32
33The typical approach uses the Perl debugger, described in the
34perldebug(1) manpage, on an "empty" program, like this:
35
36 perl -de 42
37
38Now just type in any legal Perl code, and it will be immediately
39evaluated. You can also examine the symbol table, get stack
40backtraces, check variable values, set breakpoints, and other
41operations typically found in symbolic debuggers.
42
43=head2 Is there a Perl shell?
44
45The psh (Perl sh) is currently at version 1.8. The Perl Shell is a shell
46that combines the interactive nature of a Unix shell with the power of
47Perl. The goal is a full featured shell that behaves as expected for
48normal shell activity and uses Perl syntax and functionality for
49control-flow statements and other things. You can get psh at
50http://sourceforge.net/projects/psh/ .
51
52Zoidberg is a similar project and provides a shell written in perl,
53configured in perl and operated in perl. It is intended as a login shell
54and development environment. It can be found at http://zoidberg.sf.net/
55or your local CPAN mirror.
56
57The Shell.pm module (distributed with Perl) makes Perl try commands
58which aren't part of the Perl language as shell commands. perlsh from
59the source distribution is simplistic and uninteresting, but may still
60be what you want.
61
62=head2 How do I find which modules are installed on my system?
63
64You can use the ExtUtils::Installed module to show all installed
65distributions, although it can take awhile to do its magic. The
66standard library which comes with Perl just shows up as "Perl" (although
67you can get those with Module::CoreList).
68
69 use ExtUtils::Installed;
70
71 my $inst = ExtUtils::Installed->new();
72 my @modules = $inst->modules();
73
74If you want a list of all of the Perl module filenames, you
75can use File::Find::Rule.
76
77 use File::Find::Rule;
78
79 my @files = File::Find::Rule->file()->name( '*.pm' )->in( @INC );
80
81If you do not have that module, you can do the same thing
82with File::Find which is part of the standard library.
83
84 use File::Find;
85 my @files;
86
87 find(
88 sub {
89 push @files, $File::Find::name
90 if -f $File::Find::name && /\.pm$/
91 },
92
93 @INC
94 );
95
96 print join "\n", @files;
97
98If you simply need to quickly check to see if a module is
99available, you can check for its documentation. If you can
100read the documentation the module is most likely installed.
101If you cannot read the documentation, the module might not
102have any (in rare cases).
103
104 prompt% perldoc Module::Name
105
106You can also try to include the module in a one-liner to see if
107perl finds it.
108
109 perl -MModule::Name -e1
110
111=head2 How do I debug my Perl programs?
112
113Have you tried C<use warnings> or used C<-w>? They enable warnings
114to detect dubious practices.
115
116Have you tried C<use strict>? It prevents you from using symbolic
117references, makes you predeclare any subroutines that you call as bare
118words, and (probably most importantly) forces you to predeclare your
119variables with C<my>, C<our>, or C<use vars>.
120
121Did you check the return values of each and every system call? The operating
122system (and thus Perl) tells you whether they worked, and if not
123why.
124
125 open(FH, "> /etc/cantwrite")
126 or die "Couldn't write to /etc/cantwrite: $!\n";