Commit | Line | Data |
a0d0e21e |
1 | =head1 NAME |
2 | |
3 | perl - Practical Extraction and Report Language |
4 | |
5 | =head1 SYNOPSIS |
6 | |
7 | For ease of access, the Perl manual has been split up into a number |
8 | of sections: |
9 | |
10 | perl Perl overview (this section) |
11 | perldata Perl data structures |
12 | perlsyn Perl syntax |
13 | perlop Perl operators and precedence |
14 | perlre Perl regular expressions |
15 | perlrun Perl execution and options |
16 | perlfunc Perl builtin functions |
17 | perlvar Perl predefined variables |
18 | perlsub Perl subroutines |
19 | perlmod Perl modules |
20 | perlref Perl references and nested data structures |
21 | perlobj Perl objects |
22 | perlbot Perl OO tricks and examples |
23 | perldebug Perl debugging |
24 | perldiag Perl diagnostic messages |
25 | perlform Perl formats |
26 | perlipc Perl interprocess communication |
27 | perlsec Perl security |
28 | perltrap Perl traps for the unwary |
29 | perlstyle Perl style guide |
30 | perlapi Perl application programming interface |
31 | perlguts Perl internal functions for those doing extensions |
32 | perlcall Perl calling conventions from C |
33 | perlovl Perl overloading semantics |
34 | perlbook Perl book information |
35 | |
36 | (If you're intending to read these straight through for the first time, |
37 | the suggested order will tend to reduce the number of forward references.) |
38 | |
16d20bd9 |
39 | Additional documentation for perl modules is available in |
40 | the F</usr/local/lib/perl5/man/man3> directory. You can view this |
41 | with a man(1) program by including the following in the |
42 | appropriate start-up files. (You may have to adjust the path to |
43 | match $Config{'man3dir'}.) |
44 | |
45 | .profile (for sh, bash or ksh users): |
46 | MANPATH=$MANPATH:/usr/local/lib/perl5/man |
47 | export MANPATH |
48 | |
49 | .login (for csh or tcsh users): |
50 | setenv MANPATH $MANPATH:/usr/local/lib/perl5/man |
51 | |
52 | If that doesn't work for some reason, you can still use the |
53 | supplied perldoc script to view module information. |
54 | |
a0d0e21e |
55 | If something strange has gone wrong with your program and you're not |
56 | sure where you should look for help, try the B<-w> switch first. It |
57 | will often point out exactly where the trouble is. |
58 | |
59 | =head1 DESCRIPTION |
60 | |
61 | Perl is an interpreted language optimized for scanning arbitrary |
62 | text files, extracting information from those text files, and printing |
63 | reports based on that information. It's also a good language for many |
64 | system management tasks. The language is intended to be practical |
65 | (easy to use, efficient, complete) rather than beautiful (tiny, |
66 | elegant, minimal). It combines (in the author's opinion, anyway) some |
67 | of the best features of C, B<sed>, B<awk>, and B<sh>, so people |
68 | familiar with those languages should have little difficulty with it. |
69 | (Language historians will also note some vestiges of B<csh>, Pascal, |
70 | and even BASIC-PLUS.) Expression syntax corresponds quite closely to C |
71 | expression syntax. Unlike most Unix utilities, Perl does not |
72 | arbitrarily limit the size of your data--if you've got the memory, |
73 | Perl can slurp in your whole file as a single string. Recursion is |
74 | of unlimited depth. And the hash tables used by associative arrays |
75 | grow as necessary to prevent degraded performance. Perl uses |
76 | sophisticated pattern matching techniques to scan large amounts of data |
77 | very quickly. Although optimized for scanning text, Perl can also |
78 | deal with binary data, and can make dbm files look like associative |
79 | arrays (where dbm is available). Setuid Perl scripts are safer than |
80 | C programs through a dataflow tracing mechanism which prevents many |
81 | stupid security holes. If you have a problem that would ordinarily use |
82 | B<sed> or B<awk> or B<sh>, but it exceeds their capabilities or must |
83 | run a little faster, and you don't want to write the silly thing in C, |
84 | then Perl may be for you. There are also translators to turn your |
85 | B<sed> and B<awk> scripts into Perl scripts. |
86 | |
87 | But wait, there's more... |
88 | |
89 | Perl version 5 is nearly a complete rewrite, and provides |
90 | the following additional benefits: |
91 | |
92 | =over 5 |
93 | |
94 | =item * Many usability enhancements |
95 | |
96 | It is now possible to write much more readable Perl code (even within |
97 | regular expressions). Formerly cryptic variable names can be replaced |
98 | by mnemonic identifiers. Error messages are more informative, and the |
99 | optional warnings will catch many of the mistakes a novice might make. |
100 | This cannot be stressed enough. Whenever you get mysterious behavior, |
101 | try the B<-w> switch!!! Whenever you don't get mysterious behavior, |
102 | try using B<-w> anyway. |
103 | |
104 | =item * Simplified grammar |
105 | |
106 | The new yacc grammar is one half the size of the old one. Many of the |
107 | arbitrary grammar rules have been regularized. The number of reserved |
108 | words has been cut by 2/3. Despite this, nearly all old Perl scripts |
109 | will continue to work unchanged. |
110 | |
111 | =item * Lexical scoping |
112 | |
113 | Perl variables may now be declared within a lexical scope, like "auto" |
114 | variables in C. Not only is this more efficient, but it contributes |
115 | to better privacy for "programming in the large". |
116 | |
117 | =item * Arbitrarily nested data structures |
118 | |
119 | Any scalar value, including any array element, may now contain a |
120 | reference to any other variable or subroutine. You can easily create |
121 | anonymous variables and subroutines. Perl manages your reference |
122 | counts for you. |
123 | |
124 | =item * Modularity and reusability |
125 | |
126 | The Perl library is now defined in terms of modules which can be easily |
127 | shared among various packages. A package may choose to import all or a |
128 | portion of a module's published interface. Pragmas (that is, compiler |
129 | directives) are defined and used by the same mechanism. |
130 | |
131 | =item * Object-oriented programming |
132 | |
133 | A package can function as a class. Dynamic multiple inheritance and |
134 | virtual methods are supported in a straightforward manner and with very |
135 | little new syntax. Filehandles may now be treated as objects. |
136 | |
137 | =item * Embeddible and Extensible |
138 | |
139 | Perl may now be embedded easily in your C or C++ application, and can |
140 | either call or be called by your routines through a documented |
141 | interface. The XS preprocessor is provided to make it easy to glue |
142 | your C or C++ routines into Perl. Dynamic loading of modules is |
143 | supported. |
144 | |
145 | =item * POSIX compliant |
146 | |
147 | A major new module is the POSIX module, which provides access to all |
148 | available POSIX routines and definitions, via object classes where |
149 | appropriate. |
150 | |
151 | =item * Package constructors and destructors |
152 | |
153 | The new BEGIN and END blocks provide means to capture control as |
154 | a package is being compiled, and after the program exits. As a |
155 | degenerate case they work just like awk's BEGIN and END when you |
156 | use the B<-p> or B<-n> switches. |
157 | |
158 | =item * Multiple simultaneous DBM implementations |
159 | |
160 | A Perl program may now access DBM, NDBM, SDBM, GDBM, and Berkeley DB |
161 | files from the same script simultaneously. In fact, the old dbmopen |
162 | interface has been generalized to allow any variable to be tied |
163 | to an object class which defines its access methods. |
164 | |
165 | =item * Subroutine definitions may now be autoloaded |
166 | |
167 | In fact, the AUTOLOAD mechanism also allows you to define any arbitrary |
168 | semantics for undefined subroutine calls. It's not just for autoloading. |
169 | |
170 | =item * Regular expression enhancements |
171 | |
172 | You can now specify non-greedy quantifiers. You can now do grouping |
173 | without creating a backreference. You can now write regular expressions |
174 | with embedded whitespace and comments for readability. A consistent |
175 | extensibility mechanism has been added that is upwardly compatible with |
176 | all old regular expressions. |
177 | |
178 | =back |
179 | |
180 | Ok, that's I<definitely> enough hype. |
181 | |
182 | =head1 ENVIRONMENT |
183 | |
184 | =over 12 |
185 | |
186 | =item HOME |
187 | |
188 | Used if chdir has no argument. |
189 | |
190 | =item LOGDIR |
191 | |
192 | Used if chdir has no argument and HOME is not set. |
193 | |
194 | =item PATH |
195 | |
196 | Used in executing subprocesses, and in finding the script if B<-S> is |
197 | used. |
198 | |
199 | =item PERL5LIB |
200 | |
201 | A colon-separated list of directories in which to look for Perl library |
202 | files before looking in the standard library and the current |
203 | directory. If PERL5LIB is not defined, PERLLIB is used. |
204 | |
205 | =item PERL5DB |
206 | |
207 | The command used to get the debugger code. If unset, uses |
208 | |
209 | BEGIN { require 'perl5db.pl' } |
210 | |
211 | =item PERLLIB |
212 | |
213 | A colon-separated list of directories in which to look for Perl library |
214 | files before looking in the standard library and the current |
215 | directory. If PERL5LIB is defined, PERLLIB is not used. |
216 | |
217 | |
218 | =back |
219 | |
220 | Apart from these, Perl uses no other environment variables, except |
221 | to make them available to the script being executed, and to child |
222 | processes. However, scripts running setuid would do well to execute |
223 | the following lines before doing anything else, just to keep people |
224 | honest: |
225 | |
226 | $ENV{'PATH'} = '/bin:/usr/bin'; # or whatever you need |
227 | $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'}; |
228 | $ENV{'IFS'} = '' if defined $ENV{'IFS'}; |
229 | |
230 | =head1 AUTHOR |
231 | |
232 | Larry Wall <F<lwall@netlabs.com.>, with the help of oodles of other folks. |
233 | |
234 | =head1 FILES |
235 | |
236 | "/tmp/perl-e$$" temporary file for -e commands |
237 | "@INC" locations of perl 5 libraries |
238 | |
239 | =head1 SEE ALSO |
240 | |
241 | a2p awk to perl translator |
242 | s2p sed to perl translator |
243 | |
244 | =head1 DIAGNOSTICS |
245 | |
246 | The B<-w> switch produces some lovely diagnostics. |
247 | |
248 | See L<perldiag> for explanations of all Perl's diagnostics. |
249 | |
250 | Compilation errors will tell you the line number of the error, with an |
251 | indication of the next token or token type that was to be examined. |
252 | (In the case of a script passed to Perl via B<-e> switches, each |
253 | B<-e> is counted as one line.) |
254 | |
255 | Setuid scripts have additional constraints that can produce error |
256 | messages such as "Insecure dependency". See L<perlsec>. |
257 | |
258 | Did we mention that you should definitely consider using the B<-w> |
259 | switch? |
260 | |
261 | =head1 BUGS |
262 | |
263 | The B<-w> switch is not mandatory. |
264 | |
265 | Perl is at the mercy of your machine's definitions of various |
266 | operations such as type casting, atof() and sprintf(). |
267 | |
748a9306 |
268 | If your stdio requires a seek or eof between reads and writes on a |
a0d0e21e |
269 | particular stream, so does Perl. (This doesn't apply to sysread() |
270 | and syswrite().) |
271 | |
272 | While none of the built-in data types have any arbitrary size limits |
273 | (apart from memory size), there are still a few arbitrary limits: a |
274 | given identifier may not be longer than 255 characters, and no |
275 | component of your PATH may be longer than 255 if you use B<-S>. A regular |
276 | expression may not compile to more than 32767 bytes internally. |
277 | |
278 | Perl actually stands for Pathologically Eclectic Rubbish Lister, but |
279 | don't tell anyone I said that. |
280 | |
281 | =head1 NOTES |
282 | |
283 | The Perl motto is "There's more than one way to do it." Divining |
284 | how many more is left as an exercise to the reader. |
285 | |
286 | The three principle virtues of a programmer are Laziness, |
287 | Impatience, and Hubris. See the Camel Book for why. |
16d20bd9 |
288 | |