Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "PERLFAQ3 1" | |
132 | .TH PERLFAQ3 1 "2006-01-07" "perl v5.8.8" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | perlfaq3 \- Programming Tools ($Revision: 1.56 $, $Date: 2005/12/31 00:54:37 $) | |
135 | .SH "DESCRIPTION" | |
136 | .IX Header "DESCRIPTION" | |
137 | This section of the \s-1FAQ\s0 answers questions related to programmer tools | |
138 | and programming support. | |
139 | .Sh "How do I do (anything)?" | |
140 | .IX Subsection "How do I do (anything)?" | |
141 | Have you looked at \s-1CPAN\s0 (see perlfaq2)? The chances are that | |
142 | someone has already written a module that can solve your problem. | |
143 | Have you read the appropriate manpages? Here's a brief index: | |
144 | .PP | |
145 | .Vb 12 | |
146 | \& Basics perldata, perlvar, perlsyn, perlop, perlsub | |
147 | \& Execution perlrun, perldebug | |
148 | \& Functions perlfunc | |
149 | \& Objects perlref, perlmod, perlobj, perltie | |
150 | \& Data Structures perlref, perllol, perldsc | |
151 | \& Modules perlmod, perlmodlib, perlsub | |
152 | \& Regexes perlre, perlfunc, perlop, perllocale | |
153 | \& Moving to perl5 perltrap, perl | |
154 | \& Linking w/C perlxstut, perlxs, perlcall, perlguts, perlembed | |
155 | \& Various http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz | |
156 | \& (not a man-page but still useful, a collection | |
157 | \& of various essays on Perl techniques) | |
158 | .Ve | |
159 | .PP | |
160 | A crude table of contents for the Perl manpage set is found in perltoc. | |
161 | .Sh "How can I use Perl interactively?" | |
162 | .IX Subsection "How can I use Perl interactively?" | |
163 | The typical approach uses the Perl debugger, described in the | |
164 | \&\fIperldebug\fR\|(1) manpage, on an \*(L"empty\*(R" program, like this: | |
165 | .PP | |
166 | .Vb 1 | |
167 | \& perl -de 42 | |
168 | .Ve | |
169 | .PP | |
170 | Now just type in any legal Perl code, and it will be immediately | |
171 | evaluated. You can also examine the symbol table, get stack | |
172 | backtraces, check variable values, set breakpoints, and other | |
173 | operations typically found in symbolic debuggers. | |
174 | .Sh "Is there a Perl shell?" | |
175 | .IX Subsection "Is there a Perl shell?" | |
176 | The psh (Perl sh) is currently at version 1.8. The Perl Shell is a shell | |
177 | that combines the interactive nature of a Unix shell with the power of | |
178 | Perl. The goal is a full featured shell that behaves as expected for | |
179 | normal shell activity and uses Perl syntax and functionality for | |
180 | control-flow statements and other things. You can get psh at | |
181 | http://sourceforge.net/projects/psh/ . | |
182 | .PP | |
183 | Zoidberg is a similar project and provides a shell written in perl, | |
184 | configured in perl and operated in perl. It is intended as a login shell | |
185 | and development environment. It can be found at http://zoidberg.sf.net/ | |
186 | or your local \s-1CPAN\s0 mirror. | |
187 | .PP | |
188 | The Shell.pm module (distributed with Perl) makes Perl try commands | |
189 | which aren't part of the Perl language as shell commands. perlsh from | |
190 | the source distribution is simplistic and uninteresting, but may still | |
191 | be what you want. | |
192 | .Sh "How do I find which modules are installed on my system?" | |
193 | .IX Subsection "How do I find which modules are installed on my system?" | |
194 | You can use the ExtUtils::Installed module to show all installed | |
195 | distributions, although it can take awhile to do its magic. The | |
196 | standard library which comes with Perl just shows up as \*(L"Perl\*(R" (although | |
197 | you can get those with Module::CoreList). | |
198 | .PP | |
199 | .Vb 1 | |
200 | \& use ExtUtils::Installed; | |
201 | .Ve | |
202 | .PP | |
203 | .Vb 2 | |
204 | \& my $inst = ExtUtils::Installed->new(); | |
205 | \& my @modules = $inst->modules(); | |
206 | .Ve | |
207 | .PP | |
208 | If you want a list of all of the Perl module filenames, you | |
209 | can use File::Find::Rule. | |
210 | .PP | |
211 | .Vb 1 | |
212 | \& use File::Find::Rule; | |
213 | .Ve | |
214 | .PP | |
215 | .Vb 1 | |
216 | \& my @files = File::Find::Rule->file()->name( '*.pm' )->in( @INC ); | |
217 | .Ve | |
218 | .PP | |
219 | If you do not have that module, you can do the same thing | |
220 | with File::Find which is part of the standard library. | |
221 | .PP | |
222 | .Vb 2 | |
223 | \& use File::Find; | |
224 | \& my @files; | |
225 | .Ve | |
226 | .PP | |
227 | .Vb 5 | |
228 | \& find( | |
229 | \& sub { | |
230 | \& push @files, $File::Find::name | |
231 | \& if -f $File::Find::name && /\e.pm$/ | |
232 | \& }, | |
233 | .Ve | |
234 | .PP | |
235 | .Vb 2 | |
236 | \& @INC | |
237 | \& ); | |
238 | .Ve | |
239 | .PP | |
240 | .Vb 1 | |
241 | \& print join "\en", @files; | |
242 | .Ve | |
243 | .PP | |
244 | If you simply need to quickly check to see if a module is | |
245 | available, you can check for its documentation. If you can | |
246 | read the documentation the module is most likely installed. | |
247 | If you cannot read the documentation, the module might not | |
248 | have any (in rare cases). | |
249 | .PP | |
250 | .Vb 1 | |
251 | \& prompt% perldoc Module::Name | |
252 | .Ve | |
253 | .PP | |
254 | You can also try to include the module in a one-liner to see if | |
255 | perl finds it. | |
256 | .PP | |
257 | .Vb 1 | |
258 | \& perl -MModule::Name -e1 | |
259 | .Ve | |
260 | .Sh "How do I debug my Perl programs?" | |
261 | .IX Subsection "How do I debug my Perl programs?" | |
262 | Have you tried \f(CW\*(C`use warnings\*(C'\fR or used \f(CW\*(C`\-w\*(C'\fR? They enable warnings | |
263 | to detect dubious practices. | |
264 | .PP | |
265 | Have you tried \f(CW\*(C`use strict\*(C'\fR? It prevents you from using symbolic | |
266 | references, makes you predeclare any subroutines that you call as bare | |
267 | words, and (probably most importantly) forces you to predeclare your | |
268 | variables with \f(CW\*(C`my\*(C'\fR, \f(CW\*(C`our\*(C'\fR, or \f(CW\*(C`use vars\*(C'\fR. | |
269 | .PP | |
270 | Did you check the return values of each and every system call? The operating | |
271 | system (and thus Perl) tells you whether they worked, and if not | |
272 | why. | |
273 | .PP | |
274 | .Vb 2 | |
275 | \& open(FH, "> /etc/cantwrite") | |
276 | \& or die "Couldn't write to /etc/cantwrite: $!\en"; | |
277 | .Ve | |
278 | .PP | |
279 | Did you read perltrap? It's full of gotchas for old and new Perl | |
280 | programmers and even has sections for those of you who are upgrading | |
281 | from languages like \fIawk\fR and \fIC\fR. | |
282 | .PP | |
283 | Have you tried the Perl debugger, described in perldebug? You can | |
284 | step through your program and see what it's doing and thus work out | |
285 | why what it's doing isn't what it should be doing. | |
286 | .Sh "How do I profile my Perl programs?" | |
287 | .IX Subsection "How do I profile my Perl programs?" | |
288 | You should get the Devel::DProf module from the standard distribution | |
289 | (or separately on \s-1CPAN\s0) and also use Benchmark.pm from the standard | |
290 | distribution. The Benchmark module lets you time specific portions of | |
291 | your code, while Devel::DProf gives detailed breakdowns of where your | |
292 | code spends its time. | |
293 | .PP | |
294 | Here's a sample use of Benchmark: | |
295 | .PP | |
296 | .Vb 1 | |
297 | \& use Benchmark; | |
298 | .Ve | |
299 | .PP | |
300 | .Vb 2 | |
301 | \& @junk = `cat /etc/motd`; | |
302 | \& $count = 10_000; | |
303 | .Ve | |
304 | .PP | |
305 | .Vb 8 | |
306 | \& timethese($count, { | |
307 | \& 'map' => sub { my @a = @junk; | |
308 | \& map { s/a/b/ } @a; | |
309 | \& return @a }, | |
310 | \& 'for' => sub { my @a = @junk; | |
311 | \& for (@a) { s/a/b/ }; | |
312 | \& return @a }, | |
313 | \& }); | |
314 | .Ve | |
315 | .PP | |
316 | This is what it prints (on one machine\*(--your results will be dependent | |
317 | on your hardware, operating system, and the load on your machine): | |
318 | .PP | |
319 | .Vb 3 | |
320 | \& Benchmark: timing 10000 iterations of for, map... | |
321 | \& for: 4 secs ( 3.97 usr 0.01 sys = 3.98 cpu) | |
322 | \& map: 6 secs ( 4.97 usr 0.00 sys = 4.97 cpu) | |
323 | .Ve | |
324 | .PP | |
325 | Be aware that a good benchmark is very hard to write. It only tests the | |
326 | data you give it and proves little about the differing complexities | |
327 | of contrasting algorithms. | |
328 | .Sh "How do I cross-reference my Perl programs?" | |
329 | .IX Subsection "How do I cross-reference my Perl programs?" | |
330 | The B::Xref module can be used to generate cross-reference reports | |
331 | for Perl programs. | |
332 | .PP | |
333 | .Vb 1 | |
334 | \& perl -MO=Xref[,OPTIONS] scriptname.plx | |
335 | .Ve | |
336 | .Sh "Is there a pretty-printer (formatter) for Perl?" | |
337 | .IX Subsection "Is there a pretty-printer (formatter) for Perl?" | |
338 | Perltidy is a Perl script which indents and reformats Perl scripts | |
339 | to make them easier to read by trying to follow the rules of the | |
340 | perlstyle. If you write Perl scripts, or spend much time reading | |
341 | them, you will probably find it useful. It is available at | |
342 | http://perltidy.sourceforge.net | |
343 | .PP | |
344 | Of course, if you simply follow the guidelines in perlstyle, | |
345 | you shouldn't need to reformat. The habit of formatting your code | |
346 | as you write it will help prevent bugs. Your editor can and should | |
347 | help you with this. The perl-mode or newer cperl-mode for emacs | |
348 | can provide remarkable amounts of help with most (but not all) | |
349 | code, and even less programmable editors can provide significant | |
350 | assistance. Tom Christiansen and many other \s-1VI\s0 users swear by | |
351 | the following settings in vi and its clones: | |
352 | .PP | |
353 | .Vb 2 | |
354 | \& set ai sw=4 | |
355 | \& map! ^O {^M}^[O^T | |
356 | .Ve | |
357 | .PP | |
358 | Put that in your \fI.exrc\fR file (replacing the caret characters | |
359 | with control characters) and away you go. In insert mode, ^T is | |
360 | for indenting, ^D is for undenting, and ^O is for blockdenting\*(-- | |
361 | as it were. A more complete example, with comments, can be found at | |
362 | http://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gz | |
363 | .PP | |
364 | The a2ps http://www\-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz does | |
365 | lots of things related to generating nicely printed output of | |
366 | documents, as does enscript at http://people.ssh.fi/mtr/genscript/ . | |
367 | .Sh "Is there a ctags for Perl?" | |
368 | .IX Subsection "Is there a ctags for Perl?" | |
369 | (contributed by brian d foy) | |
370 | .PP | |
371 | Exuberent ctags supports Perl: http://ctags.sourceforge.net/ | |
372 | .PP | |
373 | You might also try pltags: http://www.mscha.com/pltags.zip | |
374 | .Sh "Is there an \s-1IDE\s0 or Windows Perl Editor?" | |
375 | .IX Subsection "Is there an IDE or Windows Perl Editor?" | |
376 | Perl programs are just plain text, so any editor will do. | |
377 | .PP | |
378 | If you're on Unix, you already have an IDE\*(--Unix itself. The \s-1UNIX\s0 | |
379 | philosophy is the philosophy of several small tools that each do one | |
380 | thing and do it well. It's like a carpenter's toolbox. | |
381 | .PP | |
382 | If you want an \s-1IDE\s0, check the following (in alphabetical order, not | |
383 | order of preference): | |
384 | .IP "Eclipse" 4 | |
385 | .IX Item "Eclipse" | |
386 | http://e\-p\-i\-c.sf.net/ | |
387 | .Sp | |
388 | The Eclipse Perl Integration Project integrates Perl | |
389 | editing/debugging with Eclipse. | |
390 | .IP "Enginsite" 4 | |
391 | .IX Item "Enginsite" | |
392 | http://www.enginsite.com/ | |
393 | .Sp | |
394 | Perl Editor by EngInSite is a complete integrated development | |
395 | environment (\s-1IDE\s0) for creating, testing, and debugging Perl scripts; | |
396 | the tool runs on Windows 9x/NT/2000/XP or later. | |
397 | .IP "Komodo" 4 | |
398 | .IX Item "Komodo" | |
399 | http://www.ActiveState.com/Products/Komodo/ | |
400 | .Sp | |
401 | ActiveState's cross-platform (as of October 2004, that's Windows, Linux, | |
402 | and Solaris), multi-language \s-1IDE\s0 has Perl support, including a regular expression | |
403 | debugger and remote debugging. | |
404 | .IP "Open Perl \s-1IDE\s0" 4 | |
405 | .IX Item "Open Perl IDE" | |
406 | http://open\-perl\-ide.sourceforge.net/ | |
407 | .Sp | |
408 | Open Perl \s-1IDE\s0 is an integrated development environment for writing | |
409 | and debugging Perl scripts with ActiveState's ActivePerl distribution | |
410 | under Windows 95/98/NT/2000. | |
411 | .IP "OptiPerl" 4 | |
412 | .IX Item "OptiPerl" | |
413 | http://www.optiperl.com/ | |
414 | .Sp | |
415 | OptiPerl is a Windows \s-1IDE\s0 with simulated \s-1CGI\s0 environment, including | |
416 | debugger and syntax highlighting editor. | |
417 | .IP "PerlBuilder" 4 | |
418 | .IX Item "PerlBuilder" | |
419 | http://www.solutionsoft.com/perl.htm | |
420 | .Sp | |
421 | PerlBuidler is an integrated development environment for Windows that | |
422 | supports Perl development. | |
423 | .IP "visiPerl+" 4 | |
424 | .IX Item "visiPerl+" | |
425 | http://helpconsulting.net/visiperl/ | |
426 | .Sp | |
427 | From Help Consulting, for Windows. | |
428 | .IP "Visual Perl" 4 | |
429 | .IX Item "Visual Perl" | |
430 | http://www.activestate.com/Products/Visual_Perl/ | |
431 | .Sp | |
432 | Visual Perl is a Visual Studio.NET plug-in from ActiveState. | |
433 | .IP "Zeus" 4 | |
434 | .IX Item "Zeus" | |
435 | http://www.zeusedit.com/lookmain.html | |
436 | .Sp | |
437 | Zeus for Window is another Win32 multi-language editor/IDE | |
438 | that comes with support for Perl: | |
439 | .PP | |
440 | For editors: if you're on Unix you probably have vi or a vi clone | |
441 | already, and possibly an emacs too, so you may not need to download | |
442 | anything. In any emacs the cperl-mode (M\-x cperl\-mode) gives you | |
443 | perhaps the best available Perl editing mode in any editor. | |
444 | .PP | |
445 | If you are using Windows, you can use any editor that lets you work | |
446 | with plain text, such as NotePad or WordPad. Word processors, such as | |
447 | Microsoft Word or WordPerfect, typically do not work since they insert | |
448 | all sorts of behind-the-scenes information, although some allow you to | |
449 | save files as \*(L"Text Only\*(R". You can also download text editors designed | |
450 | specifically for programming, such as Textpad ( | |
451 | http://www.textpad.com/ ) and UltraEdit ( http://www.ultraedit.com/ ), | |
452 | among others. | |
453 | .PP | |
454 | If you are using MacOS, the same concerns apply. MacPerl (for Classic | |
455 | environments) comes with a simple editor. Popular external editors are | |
456 | BBEdit ( http://www.bbedit.com/ ) or Alpha ( | |
457 | http://www.his.com/~jguyer/Alpha/Alpha8.html ). MacOS X users can use | |
458 | Unix editors as well. Neil Bowers (the man behind Geekcruises) has a | |
459 | list of Mac editors that can handle Perl ( | |
460 | http://www.neilbowers.org/macperleditors.html ). | |
461 | .IP "\s-1GNU\s0 Emacs" 4 | |
462 | .IX Item "GNU Emacs" | |
463 | http://www.gnu.org/software/emacs/windows/ntemacs.html | |
464 | .IP "MicroEMACS" 4 | |
465 | .IX Item "MicroEMACS" | |
466 | http://www.microemacs.de/ | |
467 | .IP "XEmacs" 4 | |
468 | .IX Item "XEmacs" | |
469 | http://www.xemacs.org/Download/index.html | |
470 | .IP "Jed" 4 | |
471 | .IX Item "Jed" | |
472 | http://space.mit.edu/~davis/jed/ | |
473 | .PP | |
474 | or a vi clone such as | |
475 | .IP "Elvis" 4 | |
476 | .IX Item "Elvis" | |
477 | ftp://ftp.cs.pdx.edu/pub/elvis/ http://www.fh\-wedel.de/elvis/ | |
478 | .IP "Vile" 4 | |
479 | .IX Item "Vile" | |
480 | http://dickey.his.com/vile/vile.html | |
481 | .IP "Vim" 4 | |
482 | .IX Item "Vim" | |
483 | http://www.vim.org/ | |
484 | .PP | |
485 | For vi lovers in general, Windows or elsewhere: | |
486 | .PP | |
487 | .Vb 1 | |
488 | \& http://www.thomer.com/thomer/vi/vi.html | |
489 | .Ve | |
490 | .PP | |
491 | nvi ( http://www.bostic.com/vi/ , available from \s-1CPAN\s0 in src/misc/) is | |
492 | yet another vi clone, unfortunately not available for Windows, but in | |
493 | \&\s-1UNIX\s0 platforms you might be interested in trying it out, firstly because | |
494 | strictly speaking it is not a vi clone, it is the real vi, or the new | |
495 | incarnation of it, and secondly because you can embed Perl inside it | |
496 | to use Perl as the scripting language. nvi is not alone in this, | |
497 | though: at least also vim and vile offer an embedded Perl. | |
498 | .PP | |
499 | The following are Win32 multilanguage editor/IDESs that support Perl: | |
500 | .IP "Codewright" 4 | |
501 | .IX Item "Codewright" | |
502 | http://www.borland.com/codewright/ | |
503 | .IP "MultiEdit" 4 | |
504 | .IX Item "MultiEdit" | |
505 | http://www.MultiEdit.com/ | |
506 | .IP "SlickEdit" 4 | |
507 | .IX Item "SlickEdit" | |
508 | http://www.slickedit.com/ | |
509 | .PP | |
510 | There is also a toyedit Text widget based editor written in Perl | |
511 | that is distributed with the Tk module on \s-1CPAN\s0. The ptkdb | |
512 | ( http://world.std.com/~aep/ptkdb/ ) is a Perl/tk based debugger that | |
513 | acts as a development environment of sorts. Perl Composer | |
514 | ( http://perlcomposer.sourceforge.net/ ) is an \s-1IDE\s0 for Perl/Tk | |
515 | \&\s-1GUI\s0 creation. | |
516 | .PP | |
517 | In addition to an editor/IDE you might be interested in a more | |
518 | powerful shell environment for Win32. Your options include | |
519 | .IP "Bash" 4 | |
520 | .IX Item "Bash" | |
521 | from the Cygwin package ( http://sources.redhat.com/cygwin/ ) | |
522 | .IP "Ksh" 4 | |
523 | .IX Item "Ksh" | |
524 | from the \s-1MKS\s0 Toolkit ( http://www.mks.com/ ), or the Bourne shell of | |
525 | the U/WIN environment ( http://www.research.att.com/sw/tools/uwin/ ) | |
526 | .IP "Tcsh" 4 | |
527 | .IX Item "Tcsh" | |
528 | ftp://ftp.astron.com/pub/tcsh/ , see also | |
529 | http://www.primate.wisc.edu/software/csh\-tcsh\-book/ | |
530 | .IP "Zsh" 4 | |
531 | .IX Item "Zsh" | |
532 | ftp://ftp.blarg.net/users/amol/zsh/ , see also http://www.zsh.org/ | |
533 | .PP | |
534 | \&\s-1MKS\s0 and U/WIN are commercial (U/WIN is free for educational and | |
535 | research purposes), Cygwin is covered by the \s-1GNU\s0 Public License (but | |
536 | that shouldn't matter for Perl use). The Cygwin, \s-1MKS\s0, and U/WIN all | |
537 | contain (in addition to the shells) a comprehensive set of standard | |
538 | \&\s-1UNIX\s0 toolkit utilities. | |
539 | .PP | |
540 | If you're transferring text files between Unix and Windows using \s-1FTP\s0 | |
541 | be sure to transfer them in \s-1ASCII\s0 mode so the ends of lines are | |
542 | appropriately converted. | |
543 | .PP | |
544 | On Mac \s-1OS\s0 the MacPerl Application comes with a simple 32k text editor | |
545 | that behaves like a rudimentary \s-1IDE\s0. In contrast to the MacPerl Application | |
546 | the \s-1MPW\s0 Perl tool can make use of the \s-1MPW\s0 Shell itself as an editor (with | |
547 | no 32k limit). | |
548 | .IP "Affrus" 4 | |
549 | .IX Item "Affrus" | |
550 | is a full Perl development environment with full debugger support | |
551 | ( http://www.latenightsw.com ). | |
552 | .IP "Alpha" 4 | |
553 | .IX Item "Alpha" | |
554 | is an editor, written and extensible in Tcl, that nonetheless has | |
555 | built in support for several popular markup and programming languages | |
556 | including Perl and \s-1HTML\s0 ( http://www.his.com/~jguyer/Alpha/Alpha8.html ). | |
557 | .IP "BBEdit and BBEdit Lite" 4 | |
558 | .IX Item "BBEdit and BBEdit Lite" | |
559 | are text editors for Mac \s-1OS\s0 that have a Perl sensitivity mode | |
560 | ( http://web.barebones.com/ ). | |
561 | .PP | |
562 | Pepper and Pe are programming language sensitive text editors for Mac | |
563 | \&\s-1OS\s0 X and BeOS respectively ( http://www.hekkelman.com/ ). | |
564 | .Sh "Where can I get Perl macros for vi?" | |
565 | .IX Subsection "Where can I get Perl macros for vi?" | |
566 | For a complete version of Tom Christiansen's vi configuration file, | |
567 | see http://www.cpan.org/authors/Tom_Christiansen/scripts/toms.exrc.gz , | |
568 | the standard benchmark file for vi emulators. The file runs best with nvi, | |
569 | the current version of vi out of Berkeley, which incidentally can be built | |
570 | with an embedded Perl interpreter\*(--see http://www.cpan.org/src/misc/ . | |
571 | .Sh "Where can I get perl-mode for emacs?" | |
572 | .IX Subsection "Where can I get perl-mode for emacs?" | |
573 | Since Emacs version 19 patchlevel 22 or so, there have been both a | |
574 | perl\-mode.el and support for the Perl debugger built in. These should | |
575 | come with the standard Emacs 19 distribution. | |
576 | .PP | |
577 | In the Perl source directory, you'll find a directory called \*(L"emacs\*(R", | |
578 | which contains a cperl-mode that color-codes keywords, provides | |
579 | context-sensitive help, and other nifty things. | |
580 | .PP | |
581 | Note that the perl-mode of emacs will have fits with \f(CW"main'foo"\fR | |
582 | (single quote), and mess up the indentation and highlighting. You | |
583 | are probably using \f(CW"main::foo"\fR in new Perl code anyway, so this | |
584 | shouldn't be an issue. | |
585 | .Sh "How can I use curses with Perl?" | |
586 | .IX Subsection "How can I use curses with Perl?" | |
587 | The Curses module from \s-1CPAN\s0 provides a dynamically loadable object | |
588 | module interface to a curses library. A small demo can be found at the | |
589 | directory http://www.cpan.org/authors/Tom_Christiansen/scripts/rep.gz ; | |
590 | this program repeats a command and updates the screen as needed, rendering | |
591 | \&\fBrep ps axu\fR similar to \fBtop\fR. | |
592 | .Sh "How can I use X or Tk with Perl?" | |
593 | .IX Subsection "How can I use X or Tk with Perl?" | |
594 | Tk is a completely Perl\-based, object-oriented interface to the Tk toolkit | |
595 | that doesn't force you to use Tcl just to get at Tk. Sx is an interface | |
596 | to the Athena Widget set. Both are available from \s-1CPAN\s0. See the | |
597 | directory http://www.cpan.org/modules/by\-category/08_User_Interfaces/ | |
598 | .PP | |
599 | Invaluable for Perl/Tk programming are the Perl/Tk \s-1FAQ\s0 at | |
600 | http://phaseit.net/claird/comp.lang.perl.tk/ptkFAQ.html , the Perl/Tk Reference | |
601 | Guide available at | |
602 | http://www.cpan.org/authors/Stephen_O_Lidie/ , and the | |
603 | online manpages at | |
604 | http://www\-users.cs.umn.edu/%7Eamundson/perl/perltk/toc.html . | |
605 | .Sh "How can I make my Perl program run faster?" | |
606 | .IX Subsection "How can I make my Perl program run faster?" | |
607 | The best way to do this is to come up with a better algorithm. This | |
608 | can often make a dramatic difference. Jon Bentley's book | |
609 | \&\fIProgramming Pearls\fR (that's not a misspelling!) has some good tips | |
610 | on optimization, too. Advice on benchmarking boils down to: benchmark | |
611 | and profile to make sure you're optimizing the right part, look for | |
612 | better algorithms instead of microtuning your code, and when all else | |
613 | fails consider just buying faster hardware. You will probably want to | |
614 | read the answer to the earlier question \*(L"How do I profile my Perl | |
615 | programs?\*(R" if you haven't done so already. | |
616 | .PP | |
617 | A different approach is to autoload seldom-used Perl code. See the | |
618 | AutoSplit and AutoLoader modules in the standard distribution for | |
619 | that. Or you could locate the bottleneck and think about writing just | |
620 | that part in C, the way we used to take bottlenecks in C code and | |
621 | write them in assembler. Similar to rewriting in C, modules that have | |
622 | critical sections can be written in C (for instance, the \s-1PDL\s0 module | |
623 | from \s-1CPAN\s0). | |
624 | .PP | |
625 | If you're currently linking your perl executable to a shared | |
626 | \&\fIlibc.so\fR, you can often gain a 10\-25% performance benefit by | |
627 | rebuilding it to link with a static libc.a instead. This will make a | |
628 | bigger perl executable, but your Perl programs (and programmers) may | |
629 | thank you for it. See the \fI\s-1INSTALL\s0\fR file in the source distribution | |
630 | for more information. | |
631 | .PP | |
632 | The undump program was an ancient attempt to speed up Perl program by | |
633 | storing the already-compiled form to disk. This is no longer a viable | |
634 | option, as it only worked on a few architectures, and wasn't a good | |
635 | solution anyway. | |
636 | .Sh "How can I make my Perl program take less memory?" | |
637 | .IX Subsection "How can I make my Perl program take less memory?" | |
638 | When it comes to time-space tradeoffs, Perl nearly always prefers to | |
639 | throw memory at a problem. Scalars in Perl use more memory than | |
640 | strings in C, arrays take more than that, and hashes use even more. While | |
641 | there's still a lot to be done, recent releases have been addressing | |
642 | these issues. For example, as of 5.004, duplicate hash keys are | |
643 | shared amongst all hashes using them, so require no reallocation. | |
644 | .PP | |
645 | In some cases, using \fIsubstr()\fR or \fIvec()\fR to simulate arrays can be | |
646 | highly beneficial. For example, an array of a thousand booleans will | |
647 | take at least 20,000 bytes of space, but it can be turned into one | |
648 | 125\-byte bit vector\*(--a considerable memory savings. The standard | |
649 | Tie::SubstrHash module can also help for certain types of data | |
650 | structure. If you're working with specialist data structures | |
651 | (matrices, for instance) modules that implement these in C may use | |
652 | less memory than equivalent Perl modules. | |
653 | .PP | |
654 | Another thing to try is learning whether your Perl was compiled with | |
655 | the system malloc or with Perl's builtin malloc. Whichever one it | |
656 | is, try using the other one and see whether this makes a difference. | |
657 | Information about malloc is in the \fI\s-1INSTALL\s0\fR file in the source | |
658 | distribution. You can find out whether you are using perl's malloc by | |
659 | typing \f(CW\*(C`perl \-V:usemymalloc\*(C'\fR. | |
660 | .PP | |
661 | Of course, the best way to save memory is to not do anything to waste | |
662 | it in the first place. Good programming practices can go a long way | |
663 | toward this: | |
664 | .IP "* Don't slurp!" 4 | |
665 | .IX Item "Don't slurp!" | |
666 | Don't read an entire file into memory if you can process it line | |
667 | by line. Or more concretely, use a loop like this: | |
668 | .Sp | |
669 | .Vb 6 | |
670 | \& # | |
671 | \& # Good Idea | |
672 | \& # | |
673 | \& while (<FILE>) { | |
674 | \& # ... | |
675 | \& } | |
676 | .Ve | |
677 | .Sp | |
678 | instead of this: | |
679 | .Sp | |
680 | .Vb 7 | |
681 | \& # | |
682 | \& # Bad Idea | |
683 | \& # | |
684 | \& @data = <FILE>; | |
685 | \& foreach (@data) { | |
686 | \& # ... | |
687 | \& } | |
688 | .Ve | |
689 | .Sp | |
690 | When the files you're processing are small, it doesn't much matter which | |
691 | way you do it, but it makes a huge difference when they start getting | |
692 | larger. | |
693 | .IP "* Use map and grep selectively" 4 | |
694 | .IX Item "Use map and grep selectively" | |
695 | Remember that both map and grep expect a \s-1LIST\s0 argument, so doing this: | |
696 | .Sp | |
697 | .Vb 1 | |
698 | \& @wanted = grep {/pattern/} <FILE>; | |
699 | .Ve | |
700 | .Sp | |
701 | will cause the entire file to be slurped. For large files, it's better | |
702 | to loop: | |
703 | .Sp | |
704 | .Vb 3 | |
705 | \& while (<FILE>) { | |
706 | \& push(@wanted, $_) if /pattern/; | |
707 | \& } | |
708 | .Ve | |
709 | .IP "* Avoid unnecessary quotes and stringification" 4 | |
710 | .IX Item "Avoid unnecessary quotes and stringification" | |
711 | Don't quote large strings unless absolutely necessary: | |
712 | .Sp | |
713 | .Vb 1 | |
714 | \& my $copy = "$large_string"; | |
715 | .Ve | |
716 | .Sp | |
717 | makes 2 copies of \f(CW$large_string\fR (one for \f(CW$copy\fR and another for the | |
718 | quotes), whereas | |
719 | .Sp | |
720 | .Vb 1 | |
721 | \& my $copy = $large_string; | |
722 | .Ve | |
723 | .Sp | |
724 | only makes one copy. | |
725 | .Sp | |
726 | Ditto for stringifying large arrays: | |
727 | .Sp | |
728 | .Vb 4 | |
729 | \& { | |
730 | \& local $, = "\en"; | |
731 | \& print @big_array; | |
732 | \& } | |
733 | .Ve | |
734 | .Sp | |
735 | is much more memory-efficient than either | |
736 | .Sp | |
737 | .Vb 1 | |
738 | \& print join "\en", @big_array; | |
739 | .Ve | |
740 | .Sp | |
741 | or | |
742 | .Sp | |
743 | .Vb 4 | |
744 | \& { | |
745 | \& local $" = "\en"; | |
746 | \& print "@big_array"; | |
747 | \& } | |
748 | .Ve | |
749 | .IP "* Pass by reference" 4 | |
750 | .IX Item "Pass by reference" | |
751 | Pass arrays and hashes by reference, not by value. For one thing, it's | |
752 | the only way to pass multiple lists or hashes (or both) in a single | |
753 | call/return. It also avoids creating a copy of all the contents. This | |
754 | requires some judgment, however, because any changes will be propagated | |
755 | back to the original data. If you really want to mangle (er, modify) a | |
756 | copy, you'll have to sacrifice the memory needed to make one. | |
757 | .IP "* Tie large variables to disk." 4 | |
758 | .IX Item "Tie large variables to disk." | |
759 | For \*(L"big\*(R" data stores (i.e. ones that exceed available memory) consider | |
760 | using one of the \s-1DB\s0 modules to store it on disk instead of in \s-1RAM\s0. This | |
761 | will incur a penalty in access time, but that's probably better than | |
762 | causing your hard disk to thrash due to massive swapping. | |
763 | .Sh "Is it safe to return a reference to local or lexical data?" | |
764 | .IX Subsection "Is it safe to return a reference to local or lexical data?" | |
765 | Yes. Perl's garbage collection system takes care of this so | |
766 | everything works out right. | |
767 | .PP | |
768 | .Vb 4 | |
769 | \& sub makeone { | |
770 | \& my @a = ( 1 .. 10 ); | |
771 | \& return \e@a; | |
772 | \& } | |
773 | .Ve | |
774 | .PP | |
775 | .Vb 3 | |
776 | \& for ( 1 .. 10 ) { | |
777 | \& push @many, makeone(); | |
778 | \& } | |
779 | .Ve | |
780 | .PP | |
781 | .Vb 1 | |
782 | \& print $many[4][5], "\en"; | |
783 | .Ve | |
784 | .PP | |
785 | .Vb 1 | |
786 | \& print "@many\en"; | |
787 | .Ve | |
788 | .Sh "How can I free an array or hash so my program shrinks?" | |
789 | .IX Subsection "How can I free an array or hash so my program shrinks?" | |
790 | (contributed by Michael Carman) | |
791 | .PP | |
792 | You usually can't. Memory allocated to lexicals (i.e. \fImy()\fR variables) | |
793 | cannot be reclaimed or reused even if they go out of scope. It is | |
794 | reserved in case the variables come back into scope. Memory allocated | |
795 | to global variables can be reused (within your program) by using | |
796 | \&\fIundef()\fRing and/or \fIdelete()\fR. | |
797 | .PP | |
798 | On most operating systems, memory allocated to a program can never be | |
799 | returned to the system. That's why long-running programs sometimes re\- | |
800 | exec themselves. Some operating systems (notably, systems that use | |
801 | \&\fImmap\fR\|(2) for allocating large chunks of memory) can reclaim memory that | |
802 | is no longer used, but on such systems, perl must be configured and | |
803 | compiled to use the \s-1OS\s0's malloc, not perl's. | |
804 | .PP | |
805 | In general, memory allocation and de-allocation isn't something you can | |
806 | or should be worrying about much in Perl. | |
807 | .PP | |
808 | See also \*(L"How can I make my Perl program take less memory?\*(R" | |
809 | .Sh "How can I make my \s-1CGI\s0 script more efficient?" | |
810 | .IX Subsection "How can I make my CGI script more efficient?" | |
811 | Beyond the normal measures described to make general Perl programs | |
812 | faster or smaller, a \s-1CGI\s0 program has additional issues. It may be run | |
813 | several times per second. Given that each time it runs it will need | |
814 | to be re-compiled and will often allocate a megabyte or more of system | |
815 | memory, this can be a killer. Compiling into C \fBisn't going to help | |
816 | you\fR because the process start-up overhead is where the bottleneck is. | |
817 | .PP | |
818 | There are two popular ways to avoid this overhead. One solution | |
819 | involves running the Apache \s-1HTTP\s0 server (available from | |
820 | http://www.apache.org/ ) with either of the mod_perl or mod_fastcgi | |
821 | plugin modules. | |
822 | .PP | |
823 | With mod_perl and the Apache::Registry module (distributed with | |
824 | mod_perl), httpd will run with an embedded Perl interpreter which | |
825 | pre-compiles your script and then executes it within the same address | |
826 | space without forking. The Apache extension also gives Perl access to | |
827 | the internal server \s-1API\s0, so modules written in Perl can do just about | |
828 | anything a module written in C can. For more on mod_perl, see | |
829 | http://perl.apache.org/ | |
830 | .PP | |
831 | With the \s-1FCGI\s0 module (from \s-1CPAN\s0) and the mod_fastcgi | |
832 | module (available from http://www.fastcgi.com/ ) each of your Perl | |
833 | programs becomes a permanent \s-1CGI\s0 daemon process. | |
834 | .PP | |
835 | Both of these solutions can have far-reaching effects on your system | |
836 | and on the way you write your \s-1CGI\s0 programs, so investigate them with | |
837 | care. | |
838 | .PP | |
839 | See http://www.cpan.org/modules/by\-category/15_World_Wide_Web_HTML_HTTP_CGI/ . | |
840 | .Sh "How can I hide the source for my Perl program?" | |
841 | .IX Subsection "How can I hide the source for my Perl program?" | |
842 | Delete it. :\-) Seriously, there are a number of (mostly | |
843 | unsatisfactory) solutions with varying levels of \*(L"security\*(R". | |
844 | .PP | |
845 | First of all, however, you \fIcan't\fR take away read permission, because | |
846 | the source code has to be readable in order to be compiled and | |
847 | interpreted. (That doesn't mean that a \s-1CGI\s0 script's source is | |
848 | readable by people on the web, though\*(--only by people with access to | |
849 | the filesystem.) So you have to leave the permissions at the socially | |
850 | friendly 0755 level. | |
851 | .PP | |
852 | Some people regard this as a security problem. If your program does | |
853 | insecure things and relies on people not knowing how to exploit those | |
854 | insecurities, it is not secure. It is often possible for someone to | |
855 | determine the insecure things and exploit them without viewing the | |
856 | source. Security through obscurity, the name for hiding your bugs | |
857 | instead of fixing them, is little security indeed. | |
858 | .PP | |
859 | You can try using encryption via source filters (Starting from Perl | |
860 | 5.8 the Filter::Simple and Filter::Util::Call modules are included in | |
861 | the standard distribution), but any decent programmer will be able to | |
862 | decrypt it. You can try using the byte code compiler and interpreter | |
863 | described below, but the curious might still be able to de-compile it. | |
864 | You can try using the native-code compiler described below, but | |
865 | crackers might be able to disassemble it. These pose varying degrees | |
866 | of difficulty to people wanting to get at your code, but none can | |
867 | definitively conceal it (true of every language, not just Perl). | |
868 | .PP | |
869 | It is very easy to recover the source of Perl programs. You simply | |
870 | feed the program to the perl interpreter and use the modules in | |
871 | the B:: hierarchy. The B::Deparse module should be able to | |
872 | defeat most attempts to hide source. Again, this is not | |
873 | unique to Perl. | |
874 | .PP | |
875 | If you're concerned about people profiting from your code, then the | |
876 | bottom line is that nothing but a restrictive license will give you | |
877 | legal security. License your software and pepper it with threatening | |
878 | statements like \*(L"This is unpublished proprietary software of \s-1XYZ\s0 Corp. | |
879 | Your access to it does not give you permission to use it blah blah | |
880 | blah.\*(R" We are not lawyers, of course, so you should see a lawyer if | |
881 | you want to be sure your license's wording will stand up in court. | |
882 | .Sh "How can I compile my Perl program into byte code or C?" | |
883 | .IX Subsection "How can I compile my Perl program into byte code or C?" | |
884 | (contributed by brian d foy) | |
885 | .PP | |
886 | In general, you can't do this. There are some things that may work | |
887 | for your situation though. People usually ask this question | |
888 | because they want to distribute their works without giving away | |
889 | the source code, and most solutions trade disk space for convenience. | |
890 | You probably won't see much of a speed increase either, since most | |
891 | solutions simply bundle a Perl interpreter in the final product | |
892 | (but see \*(L"How can I make my Perl program run faster?\*(R"). | |
893 | .PP | |
894 | The Perl Archive Toolkit ( http://par.perl.org/index.cgi ) is Perl's | |
895 | analog to Java's \s-1JAR\s0. It's freely available and on \s-1CPAN\s0 ( | |
896 | http://search.cpan.org/dist/PAR/ ). | |
897 | .PP | |
898 | The B::* namespace, often called \*(L"the Perl compiler\*(R", but is really a way | |
899 | for Perl programs to peek at its innards rather than create pre-compiled | |
900 | versions of your program. However. the B::Bytecode module can turn your | |
901 | script into a bytecode format that could be loaded later by the | |
902 | ByteLoader module and executed as a regular Perl script. | |
903 | .PP | |
904 | There are also some commercial products that may work for you, although | |
905 | you have to buy a license for them. | |
906 | .PP | |
907 | The Perl Dev Kit ( http://www.activestate.com/Products/Perl_Dev_Kit/ ) | |
908 | from ActiveState can \*(L"Turn your Perl programs into ready-to-run | |
909 | executables for \s-1HP\-UX\s0, Linux, Solaris and Windows.\*(R" | |
910 | .PP | |
911 | Perl2Exe ( http://www.indigostar.com/perl2exe.htm ) is a command line | |
912 | program for converting perl scripts to executable files. It targets both | |
913 | Windows and unix platforms. | |
914 | .Sh "How can I compile Perl into Java?" | |
915 | .IX Subsection "How can I compile Perl into Java?" | |
916 | You can also integrate Java and Perl with the | |
917 | Perl Resource Kit from O'Reilly Media. See | |
918 | http://www.oreilly.com/catalog/prkunix/ . | |
919 | .PP | |
920 | Perl 5.6 comes with Java Perl Lingo, or \s-1JPL\s0. \s-1JPL\s0, still in | |
921 | development, allows Perl code to be called from Java. See jpl/README | |
922 | in the Perl source tree. | |
923 | .ie n .Sh "How can I get ""#!perl"" to work on [\s-1MS\-DOS\s0,NT,...]?" | |
924 | .el .Sh "How can I get \f(CW#!perl\fP to work on [\s-1MS\-DOS\s0,NT,...]?" | |
925 | .IX Subsection "How can I get #!perl to work on [MS-DOS,NT,...]?" | |
926 | For \s-1OS/2\s0 just use | |
927 | .PP | |
928 | .Vb 1 | |
929 | \& extproc perl -S -your_switches | |
930 | .Ve | |
931 | .PP | |
932 | as the first line in \f(CW\*(C`*.cmd\*(C'\fR file (\f(CW\*(C`\-S\*(C'\fR due to a bug in cmd.exe's | |
933 | \&\*(L"extproc\*(R" handling). For \s-1DOS\s0 one should first invent a corresponding | |
934 | batch file and codify it in \f(CW\*(C`ALTERNATE_SHEBANG\*(C'\fR (see the | |
935 | \&\fIdosish.h\fR file in the source distribution for more information). | |
936 | .PP | |
937 | The Win95/NT installation, when using the ActiveState port of Perl, | |
938 | will modify the Registry to associate the \f(CW\*(C`.pl\*(C'\fR extension with the | |
939 | perl interpreter. If you install another port, perhaps even building | |
940 | your own Win95/NT Perl from the standard sources by using a Windows port | |
941 | of gcc (e.g., with cygwin or mingw32), then you'll have to modify | |
942 | the Registry yourself. In addition to associating \f(CW\*(C`.pl\*(C'\fR with the | |
943 | interpreter, \s-1NT\s0 people can use: \f(CW\*(C`SET PATHEXT=%PATHEXT%;.PL\*(C'\fR to let them | |
944 | run the program \f(CW\*(C`install\-linux.pl\*(C'\fR merely by typing \f(CW\*(C`install\-linux\*(C'\fR. | |
945 | .PP | |
946 | Under \*(L"Classic\*(R" MacOS, a perl program will have the appropriate Creator and | |
947 | Type, so that double-clicking them will invoke the MacPerl application. | |
948 | Under Mac \s-1OS\s0 X, clickable apps can be made from any \f(CW\*(C`#!\*(C'\fR script using Wil | |
949 | Sanchez' DropScript utility: http://www.wsanchez.net/software/ . | |
950 | .PP | |
951 | \&\fI\s-1IMPORTANT\s0!\fR: Whatever you do, \s-1PLEASE\s0 don't get frustrated, and just | |
952 | throw the perl interpreter into your cgi-bin directory, in order to | |
953 | get your programs working for a web server. This is an \s-1EXTREMELY\s0 big | |
954 | security risk. Take the time to figure out how to do it correctly. | |
955 | .Sh "Can I write useful Perl programs on the command line?" | |
956 | .IX Subsection "Can I write useful Perl programs on the command line?" | |
957 | Yes. Read perlrun for more information. Some examples follow. | |
958 | (These assume standard Unix shell quoting rules.) | |
959 | .PP | |
960 | .Vb 2 | |
961 | \& # sum first and last fields | |
962 | \& perl -lane 'print $F[0] + $F[-1]' * | |
963 | .Ve | |
964 | .PP | |
965 | .Vb 2 | |
966 | \& # identify text files | |
967 | \& perl -le 'for(@ARGV) {print if -f && -T _}' * | |
968 | .Ve | |
969 | .PP | |
970 | .Vb 2 | |
971 | \& # remove (most) comments from C program | |
972 | \& perl -0777 -pe 's{/\e*.*?\e*/}{}gs' foo.c | |
973 | .Ve | |
974 | .PP | |
975 | .Vb 2 | |
976 | \& # make file a month younger than today, defeating reaper daemons | |
977 | \& perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' * | |
978 | .Ve | |
979 | .PP | |
980 | .Vb 2 | |
981 | \& # find first unused uid | |
982 | \& perl -le '$i++ while getpwuid($i); print $i' | |
983 | .Ve | |
984 | .PP | |
985 | .Vb 3 | |
986 | \& # display reasonable manpath | |
987 | \& echo $PATH | perl -nl -072 -e ' | |
988 | \& s![^/+]*$!man!&&-d&&!$s{$_}++&&push@m,$_;END{print"@m"}' | |
989 | .Ve | |
990 | .PP | |
991 | \&\s-1OK\s0, the last one was actually an Obfuscated Perl Contest entry. :\-) | |
992 | .Sh "Why don't Perl one-liners work on my DOS/Mac/VMS system?" | |
993 | .IX Subsection "Why don't Perl one-liners work on my DOS/Mac/VMS system?" | |
994 | The problem is usually that the command interpreters on those systems | |
995 | have rather different ideas about quoting than the Unix shells under | |
996 | which the one-liners were created. On some systems, you may have to | |
997 | change single-quotes to double ones, which you must \fI\s-1NOT\s0\fR do on Unix | |
998 | or Plan9 systems. You might also have to change a single % to a %%. | |
999 | .PP | |
1000 | For example: | |
1001 | .PP | |
1002 | .Vb 2 | |
1003 | \& # Unix | |
1004 | \& perl -e 'print "Hello world\en"' | |
1005 | .Ve | |
1006 | .PP | |
1007 | .Vb 2 | |
1008 | \& # DOS, etc. | |
1009 | \& perl -e "print \e"Hello world\en\e"" | |
1010 | .Ve | |
1011 | .PP | |
1012 | .Vb 3 | |
1013 | \& # Mac | |
1014 | \& print "Hello world\en" | |
1015 | \& (then Run "Myscript" or Shift-Command-R) | |
1016 | .Ve | |
1017 | .PP | |
1018 | .Vb 2 | |
1019 | \& # MPW | |
1020 | \& perl -e 'print "Hello world\en"' | |
1021 | .Ve | |
1022 | .PP | |
1023 | .Vb 2 | |
1024 | \& # VMS | |
1025 | \& perl -e "print ""Hello world\en""" | |
1026 | .Ve | |
1027 | .PP | |
1028 | The problem is that none of these examples are reliable: they depend on the | |
1029 | command interpreter. Under Unix, the first two often work. Under \s-1DOS\s0, | |
1030 | it's entirely possible that neither works. If 4DOS was the command shell, | |
1031 | you'd probably have better luck like this: | |
1032 | .PP | |
1033 | .Vb 1 | |
1034 | \& perl -e "print <Ctrl-x>"Hello world\en<Ctrl-x>"" | |
1035 | .Ve | |
1036 | .PP | |
1037 | Under the Mac, it depends which environment you are using. The MacPerl | |
1038 | shell, or \s-1MPW\s0, is much like Unix shells in its support for several | |
1039 | quoting variants, except that it makes free use of the Mac's non-ASCII | |
1040 | characters as control characters. | |
1041 | .PP | |
1042 | Using \fIqq()\fR, q(), and \fIqx()\fR, instead of \*(L"double quotes\*(R", 'single | |
1043 | quotes', and `backticks`, may make one-liners easier to write. | |
1044 | .PP | |
1045 | There is no general solution to all of this. It is a mess. | |
1046 | .PP | |
1047 | [Some of this answer was contributed by Kenneth Albanowski.] | |
1048 | .Sh "Where can I learn about \s-1CGI\s0 or Web programming in Perl?" | |
1049 | .IX Subsection "Where can I learn about CGI or Web programming in Perl?" | |
1050 | For modules, get the \s-1CGI\s0 or \s-1LWP\s0 modules from \s-1CPAN\s0. For textbooks, | |
1051 | see the two especially dedicated to web stuff in the question on | |
1052 | books. For problems and questions related to the web, like \*(L"Why | |
1053 | do I get 500 Errors\*(R" or \*(L"Why doesn't it run from the browser right | |
1054 | when it runs fine on the command line\*(R", see the troubleshooting | |
1055 | guides and references in perlfaq9 or in the \s-1CGI\s0 MetaFAQ: | |
1056 | .PP | |
1057 | .Vb 1 | |
1058 | \& http://www.perl.org/CGI_MetaFAQ.html | |
1059 | .Ve | |
1060 | .Sh "Where can I learn about object-oriented Perl programming?" | |
1061 | .IX Subsection "Where can I learn about object-oriented Perl programming?" | |
1062 | A good place to start is perltoot, and you can use perlobj, | |
1063 | perlboot, perltoot, perltooc, and perlbot for reference. | |
1064 | .PP | |
1065 | A good book on \s-1OO\s0 on Perl is the \*(L"Object\-Oriented Perl\*(R" | |
1066 | by Damian Conway from Manning Publications, or \*(L"Learning Perl | |
1067 | References, Objects, & Modules\*(R" by Randal Schwartz and Tom | |
1068 | Phoenix from O'Reilly Media. | |
1069 | .Sh "Where can I learn about linking C with Perl?" | |
1070 | .IX Subsection "Where can I learn about linking C with Perl?" | |
1071 | If you want to call C from Perl, start with perlxstut, | |
1072 | moving on to perlxs, xsubpp, and perlguts. If you want to | |
1073 | call Perl from C, then read perlembed, perlcall, and | |
1074 | perlguts. Don't forget that you can learn a lot from looking at | |
1075 | how the authors of existing extension modules wrote their code and | |
1076 | solved their problems. | |
1077 | .PP | |
1078 | You might not need all the power of \s-1XS\s0. The Inline::C module lets | |
1079 | you put C code directly in your Perl source. It handles all the | |
1080 | magic to make it work. You still have to learn at least some of | |
1081 | the perl \s-1API\s0 but you won't have to deal with the complexity of the | |
1082 | \&\s-1XS\s0 support files. | |
1083 | .Sh "I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong?" | |
1084 | .IX Subsection "I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong?" | |
1085 | Download the ExtUtils::Embed kit from \s-1CPAN\s0 and run `make test'. If | |
1086 | the tests pass, read the pods again and again and again. If they | |
1087 | fail, see perlbug and send a bug report with the output of | |
1088 | \&\f(CW\*(C`make test TEST_VERBOSE=1\*(C'\fR along with \f(CW\*(C`perl \-V\*(C'\fR. | |
1089 | .Sh "When I tried to run my script, I got this message. What does it mean?" | |
1090 | .IX Subsection "When I tried to run my script, I got this message. What does it mean?" | |
1091 | A complete list of Perl's error messages and warnings with explanatory | |
1092 | text can be found in perldiag. You can also use the splain program | |
1093 | (distributed with Perl) to explain the error messages: | |
1094 | .PP | |
1095 | .Vb 2 | |
1096 | \& perl program 2>diag.out | |
1097 | \& splain [-v] [-p] diag.out | |
1098 | .Ve | |
1099 | .PP | |
1100 | or change your program to explain the messages for you: | |
1101 | .PP | |
1102 | .Vb 1 | |
1103 | \& use diagnostics; | |
1104 | .Ve | |
1105 | .PP | |
1106 | or | |
1107 | .PP | |
1108 | .Vb 1 | |
1109 | \& use diagnostics -verbose; | |
1110 | .Ve | |
1111 | .Sh "What's MakeMaker?" | |
1112 | .IX Subsection "What's MakeMaker?" | |
1113 | This module (part of the standard Perl distribution) is designed to | |
1114 | write a Makefile for an extension module from a Makefile.PL. For more | |
1115 | information, see ExtUtils::MakeMaker. | |
1116 | .SH "AUTHOR AND COPYRIGHT" | |
1117 | .IX Header "AUTHOR AND COPYRIGHT" | |
1118 | Copyright (c) 1997\-2006 Tom Christiansen, Nathan Torkington, and | |
1119 | other authors as noted. All rights reserved. | |
1120 | .PP | |
1121 | This documentation is free; you can redistribute it and/or modify it | |
1122 | under the same terms as Perl itself. | |
1123 | .PP | |
1124 | Irrespective of its distribution, all code examples here are in the public | |
1125 | domain. You are permitted and encouraged to use this code and any | |
1126 | derivatives thereof in your own programs for fun or for profit as you | |
1127 | see fit. A simple comment in the code giving credit to the \s-1FAQ\s0 would | |
1128 | be courteous but is not required. |