Debian Codegraph @

upstream/opensuse-tumbleweed/man1/perlfaq3.1

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "PERLFAQ3 1"
61 .TH PERLFAQ3 1 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 perlfaq3 \- Programming Tools
68 .SH VERSION
69 .IX Header "VERSION"
70 version 5.20250619
71 .SH DESCRIPTION
72 .IX Header "DESCRIPTION"
73 This section of the FAQ answers questions related to programmer tools
74 and programming support.
75 .SS "How do I do (anything)?"
76 .IX Subsection "How do I do (anything)?"
77 Have you looked at CPAN (see perlfaq2)? The chances are that
78 someone has already written a module that can solve your problem.
79 Have you read the appropriate manpages? Here\*(Aqs a brief index:
80 .IP Basics 4
81 .IX Item "Basics"
82 .RS 4
83 .PD 0
84 .IP "perldata \- Perl data types" 4
85 .IX Item "perldata - Perl data types"
86 .IP "perlvar \- Perl pre\-defined variables" 4
87 .IX Item "perlvar - Perl pre-defined variables"
88 .IP "perlsyn \- Perl syntax" 4
89 .IX Item "perlsyn - Perl syntax"
90 .IP "perlop \- Perl operators and precedence" 4
91 .IX Item "perlop - Perl operators and precedence"
92 .IP "perlsub \- Perl subroutines" 4
93 .IX Item "perlsub - Perl subroutines"
94 .PD
95 .RE
96 .RS 4
97 .RE
98 .IP Execution 4
99 .IX Item "Execution"
100 .RS 4
101 .PD 0
102 .IP "perlrun \- how to execute the Perl interpreter" 4
103 .IX Item "perlrun - how to execute the Perl interpreter"
104 .IP "perldebug \- Perl debugging" 4
105 .IX Item "perldebug - Perl debugging"
106 .PD
107 .RE
108 .RS 4
109 .RE
110 .IP Functions 4
111 .IX Item "Functions"
112 .RS 4
113 .PD 0
114 .IP "perlfunc \- Perl builtin functions" 4
115 .IX Item "perlfunc - Perl builtin functions"
116 .PD
117 .RE
118 .RS 4
119 .RE
120 .IP Objects 4
121 .IX Item "Objects"
122 .RS 4
123 .PD 0
124 .IP "perlref \- Perl references and nested data structures" 4
125 .IX Item "perlref - Perl references and nested data structures"
126 .IP "perlmod \- Perl modules (packages and symbol tables)" 4
127 .IX Item "perlmod - Perl modules (packages and symbol tables)"
128 .IP "perlobj \- Perl objects" 4
129 .IX Item "perlobj - Perl objects"
130 .IP "perltie \- how to hide an object class in a simple variable" 4
131 .IX Item "perltie - how to hide an object class in a simple variable"
132 .PD
133 .RE
134 .RS 4
135 .RE
136 .IP "Data Structures" 4
137 .IX Item "Data Structures"
138 .RS 4
139 .PD 0
140 .IP "perlref \- Perl references and nested data structures" 4
141 .IX Item "perlref - Perl references and nested data structures"
142 .IP "perllol \- Manipulating arrays of arrays in Perl" 4
143 .IX Item "perllol - Manipulating arrays of arrays in Perl"
144 .IP "perldsc \- Perl Data Structures Cookbook" 4
145 .IX Item "perldsc - Perl Data Structures Cookbook"
146 .PD
147 .RE
148 .RS 4
149 .RE
150 .IP Modules 4
151 .IX Item "Modules"
152 .RS 4
153 .PD 0
154 .IP "perlmod \- Perl modules (packages and symbol tables)" 4
155 .IX Item "perlmod - Perl modules (packages and symbol tables)"
156 .IP "perlmodlib \- constructing new Perl modules and finding existing ones" 4
157 .IX Item "perlmodlib - constructing new Perl modules and finding existing ones"
158 .PD
159 .RE
160 .RS 4
161 .RE
162 .IP Regexes 4
163 .IX Item "Regexes"
164 .RS 4
165 .PD 0
166 .IP "perlre \- Perl regular expressions" 4
167 .IX Item "perlre - Perl regular expressions"
168 .IP "perlfunc \- Perl builtin functions" 4
169 .IX Item "perlfunc - Perl builtin functions"
170 .IP "perlop \- Perl operators and precedence" 4
171 .IX Item "perlop - Perl operators and precedence"
172 .IP "perllocale \- Perl locale handling (internationalization and localization)" 4
173 .IX Item "perllocale - Perl locale handling (internationalization and localization)"
174 .PD
175 .RE
176 .RS 4
177 .RE
178 .IP "Moving to perl5" 4
179 .IX Item "Moving to perl5"
180 .RS 4
181 .PD 0
182 .IP "perltrap \- Perl traps for the unwary" 4
183 .IX Item "perltrap - Perl traps for the unwary"
184 .IP perl 4
185 .IX Item "perl"
186 .PD
187 .RE
188 .RS 4
189 .RE
190 .IP "Linking with C" 4
191 .IX Item "Linking with C"
192 .RS 4
193 .PD 0
194 .IP "perlxstut \- Tutorial for writing XSUBs" 4
195 .IX Item "perlxstut - Tutorial for writing XSUBs"
196 .IP "perlxs \- XS language reference manual" 4
197 .IX Item "perlxs - XS language reference manual"
198 .IP "perlcall \- Perl calling conventions from C" 4
199 .IX Item "perlcall - Perl calling conventions from C"
200 .IP "perlguts \- Introduction to the Perl API" 4
201 .IX Item "perlguts - Introduction to the Perl API"
202 .IP "perlembed \- how to embed perl in your C program" 4
203 .IX Item "perlembed - how to embed perl in your C program"
204 .PD
205 .RE
206 .RS 4
207 .RE
208 .IP Various 4
209 .IX Item "Various"
210 <http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz>
211 (not a man\-page but still useful, a collection of various essays on
212 Perl techniques)
213 .PP
214 A crude table of contents for the Perl manpage set is found in perltoc.
215 .SS "How can I use Perl interactively?"
216 .IX Subsection "How can I use Perl interactively?"
217 The typical approach uses the Perl debugger, described in the
218 \&\fBperldebug\fR\|(1) manpage, on an "empty" program, like this:
219 .PP
220 .Vb 1
221 \& perl \-de 42
222 .Ve
223 .PP
224 Now just type in any legal Perl code, and it will be immediately
225 evaluated. You can also examine the symbol table, get stack
226 backtraces, check variable values, set breakpoints, and other
227 operations typically found in symbolic debuggers.
228 .PP
229 You can also use Devel::REPL which is an interactive shell for Perl,
230 commonly known as a REPL \- Read, Evaluate, Print, Loop. It provides
231 various handy features.
232 .SS "How do I find which modules are installed on my system?"
233 .IX Subsection "How do I find which modules are installed on my system?"
234 From the command line, you can use the \f(CW\*(C`cpan\*(C'\fR command\*(Aqs \f(CW\*(C`\-l\*(C'\fR switch:
235 .PP
236 .Vb 1
237 \& $ cpan \-l
238 .Ve
239 .PP
240 You can also use \f(CW\*(C`cpan\*(C'\fR\*(Aqs \f(CW\*(C`\-a\*(C'\fR switch to create an autobundle file
241 that \f(CW\*(C`CPAN.pm\*(C'\fR understands and can use to re\-install every module:
242 .PP
243 .Vb 1
244 \& $ cpan \-a
245 .Ve
246 .PP
247 Inside a Perl program, you can use the ExtUtils::Installed module to
248 show all installed distributions, although it can take a while to do
249 its magic. The standard library which comes with Perl just shows up
250 as "Perl" (although you can get those with Module::CoreList).
251 .PP
252 .Vb 1
253 \& use ExtUtils::Installed;
254 \&
255 \& my $inst = ExtUtils::Installed\->new();
256 \& my @modules = $inst\->modules();
257 .Ve
258 .PP
259 If you want a list of all of the Perl module filenames, you
260 can use File::Find::Rule:
261 .PP
262 .Vb 1
263 \& use File::Find::Rule;
264 \&
265 \& my @files = File::Find::Rule\->
266 \& extras({follow => 1})\->
267 \& file()\->
268 \& name( \*(Aq*.pm\*(Aq )\->
269 \& in( @INC )
270 \& ;
271 .Ve
272 .PP
273 If you do not have that module, you can do the same thing
274 with File::Find which is part of the standard library:
275 .PP
276 .Vb 2
277 \& use File::Find;
278 \& my @files;
279 \&
280 \& find(
281 \& {
282 \& wanted => sub {
283 \& push @files, $File::Find::fullname
284 \& if \-f $File::Find::fullname && /\e.pm$/
285 \& },
286 \& follow => 1,
287 \& follow_skip => 2,
288 \& },
289 \& @INC
290 \& );
291 \&
292 \& print join "\en", @files;
293 .Ve
294 .PP
295 If you simply need to check quickly to see if a module is
296 available, you can check for its documentation. If you can
297 read the documentation the module is most likely installed.
298 If you cannot read the documentation, the module might not
299 have any (in rare cases):
300 .PP
301 .Vb 1
302 \& $ perldoc Module::Name
303 .Ve
304 .PP
305 You can also try to include the module in a one\-liner to see if
306 perl finds it:
307 .PP
308 .Vb 1
309 \& $ perl \-MModule::Name \-e1
310 .Ve
311 .PP
312 (If you don\*(Aqt receive a "Can\*(Aqt locate ... in \f(CW@INC\fR" error message, then Perl
313 found the module name you asked for.)
314 .SS "How do I debug my Perl programs?"
315 .IX Subsection "How do I debug my Perl programs?"
316 (contributed by brian d foy)
317 .PP
318 Before you do anything else, you can help yourself by ensuring that
319 you let Perl tell you about problem areas in your code. By turning
320 on warnings and strictures, you can head off many problems before
321 they get too big. You can find out more about these in strict
322 and warnings.
323 .PP
324 .Vb 3
325 \& #!/usr/bin/perl
326 \& use strict;
327 \& use warnings;
328 .Ve
329 .PP
330 Beyond that, the simplest debugger is the \f(CW\*(C`print\*(C'\fR function. Use it
331 to look at values as you run your program:
332 .PP
333 .Vb 1
334 \& print STDERR "The value is [$value]\en";
335 .Ve
336 .PP
337 The Data::Dumper module can pretty\-print Perl data structures:
338 .PP
339 .Vb 2
340 \& use Data::Dumper qw( Dumper );
341 \& print STDERR "The hash is " . Dumper( \e%hash ) . "\en";
342 .Ve
343 .PP
344 Perl comes with an interactive debugger, which you can start with the
345 \&\f(CW\*(C`\-d\*(C'\fR switch. It\*(Aqs fully explained in perldebug.
346 .PP
347 If you\*(Aqd like a graphical user interface and you have Tk, you can use
348 \&\f(CW\*(C`ptkdb\*(C'\fR. It\*(Aqs on CPAN and available for free.
349 .PP
350 If you need something much more sophisticated and controllable, Leon
351 Brocard\*(Aqs Devel::ebug (which you can call with the \f(CW\*(C`\-D\*(C'\fR switch as \f(CW\*(C`\-Debug\*(C'\fR)
352 gives you the programmatic hooks into everything you need to write your
353 own (without too much pain and suffering).
354 .PP
355 You can also use a commercial debugger such as Affrus (Mac OS X), Komodo
356 from Activestate (Windows and Mac OS X), or EPIC (most platforms).
357 .SS "How do I profile my Perl programs?"
358 .IX Subsection "How do I profile my Perl programs?"
359 (contributed by brian d foy, updated Fri Jul 25 12:22:26 PDT 2008)
360 .PP
361 The \f(CW\*(C`Devel\*(C'\fR namespace has several modules which you can use to
362 profile your Perl programs.
363 .PP
364 The Devel::NYTProf (New York Times Profiler) does both statement
365 and subroutine profiling. It\*(Aqs available from CPAN and you also invoke
366 it with the \f(CW\*(C`\-d\*(C'\fR switch:
367 .PP
368 .Vb 1
369 \& perl \-d:NYTProf some_perl.pl
370 .Ve
371 .PP
372 It creates a database of the profile information that you can turn into
373 reports. The \f(CW\*(C`nytprofhtml\*(C'\fR command turns the data into an HTML report
374 similar to the Devel::Cover report:
375 .PP
376 .Vb 1
377 \& nytprofhtml
378 .Ve
379 .PP
380 You might also be interested in using the Benchmark to
381 measure and compare code snippets.
382 .PP
383 You can read more about profiling in \fIProgramming Perl\fR, chapter 20,
384 or \fIMastering Perl\fR, chapter 5.
385 .PP
386 perldebguts documents creating a custom debugger if you need to
387 create a special sort of profiler. brian d foy describes the process
388 in \fIThe Perl Journal\fR, "Creating a Perl Debugger",
389 <https://drdobbs.com/creating\-a\-perl\-debugger/184404522> , and
390 "Profiling in Perl" <https://drdobbs.com/profiling\-in\-perl/184404580> .
391 .PP
392 Perl.com has two interesting articles on profiling: "Profiling Perl",
393 by Simon Cozens, <https://www.perl.com/pub/2004/06/25/profiling.html/>
394 and "Debugging and Profiling mod_perl Applications", by Frank Wiles,
395 <http://www.perl.com/pub/a/2006/02/09/debug_mod_perl.html> .
396 .PP
397 Randal L. Schwartz writes about profiling in "Speeding up Your Perl
398 Programs" for \fIUnix Review\fR,
399 <http://www.stonehenge.com/merlyn/UnixReview/col49.html> , and "Profiling
400 in Template Toolkit via Overriding" for \fILinux Magazine\fR,
401 <http://www.stonehenge.com/merlyn/LinuxMag/col75.html> .
402 .SS "How do I cross\-reference my Perl programs?"
403 .IX Subsection "How do I cross-reference my Perl programs?"
404 The B::Xref module can be used to generate cross\-reference reports
405 for Perl programs.
406 .PP
407 .Vb 1
408 \& perl \-MO=Xref[,OPTIONS] scriptname.plx
409 .Ve
410 .SS "Is there a pretty\-printer (formatter) for Perl?"
411 .IX Subsection "Is there a pretty-printer (formatter) for Perl?"
412 Perl::Tidy comes with a perl script perltidy which indents and
413 reformats Perl scripts to make them easier to read by trying to follow
414 the rules of the perlstyle. If you write Perl, or spend much time reading
415 Perl, you will probably find it useful.
416 .PP
417 Of course, if you simply follow the guidelines in perlstyle,
418 you shouldn\*(Aqt need to reformat. The habit of formatting your code
419 as you write it will help prevent bugs. Your editor can and should
420 help you with this. The perl\-mode or newer cperl\-mode for emacs
421 can provide remarkable amounts of help with most (but not all)
422 code, and even less programmable editors can provide significant
423 assistance. Tom Christiansen and many other VI users swear by
424 the following settings in vi and its clones:
425 .PP
426 .Vb 2
427 \& set ai sw=4
428 \& map! ^O {^M}^[O^T
429 .Ve
430 .PP
431 Put that in your \fI.exrc\fR file (replacing the caret characters
432 with control characters) and away you go. In insert mode, ^T is
433 for indenting, ^D is for undenting, and ^O is for blockdenting\-\-as
434 it were. A more complete example, with comments, can be found at
435 <http://www.cpan.org/authors/id/T/TO/TOMC/scripts/toms.exrc.gz>
436 .SS "Is there an IDE or Windows Perl Editor?"
437 .IX Subsection "Is there an IDE or Windows Perl Editor?"
438 Perl programs are just plain text, so any editor will do.
439 .PP
440 If you\*(Aqre on Unix, you already have an IDE\-\-Unix itself. The Unix
441 philosophy is the philosophy of several small tools that each do one
442 thing and do it well. It\*(Aqs like a carpenter\*(Aqs toolbox.
443 .PP
444 If you want an IDE, check the following (in alphabetical order, not
445 order of preference):
446 .IP Eclipse 4
447 .IX Item "Eclipse"
448 <http://e\-p\-i\-c.sf.net/>
449 .Sp
450 The Eclipse Perl Integration Project integrates Perl
451 editing/debugging with Eclipse.
452 .IP EngInSite 4
453 .IX Item "EngInSite"
454 <http://www.enginsite.com/>
455 .Sp
456 Perl Editor by EngInSite is a complete integrated development
457 environment (IDE) for creating, testing, and debugging Perl scripts;
458 the tool runs on Windows 9x/NT/2000/XP or later.
459 .IP "IntelliJ IDEA" 4
460 .IX Item "IntelliJ IDEA"
461 <https://plugins.jetbrains.com/plugin/7796>
462 .Sp
463 Camelcade plugin provides Perl5 support in IntelliJ IDEA and other JetBrains IDEs.
464 .IP Kephra 4
465 .IX Item "Kephra"
466 <http://kephra.sf.net>
467 .Sp
468 GUI editor written in Perl using wxWidgets and Scintilla with lots of smaller features.
469 Aims for a UI based on Perl principles like TIMTOWTDI and "easy things should be easy,
470 hard things should be possible".
471 .IP Komodo 4
472 .IX Item "Komodo"
473 <http://www.ActiveState.com/Products/Komodo/>
474 .Sp
475 ActiveState\*(Aqs cross\-platform (as of October 2004, that\*(Aqs Windows, Linux,
476 and Solaris), multi\-language IDE has Perl support, including a regular expression
477 debugger and remote debugging.
478 .IP Notepad++ 4
479 .IX Item "Notepad++"
480 <http://notepad\-plus.sourceforge.net/>
481 .IP "Open Perl IDE" 4
482 .IX Item "Open Perl IDE"
483 <http://open\-perl\-ide.sourceforge.net/>
484 .Sp
485 Open Perl IDE is an integrated development environment for writing
486 and debugging Perl scripts with ActiveState\*(Aqs ActivePerl distribution
487 under Windows 95/98/NT/2000.
488 .IP OptiPerl 4
489 .IX Item "OptiPerl"
490 <https://www.uptiv.com/free/optiperl/>
491 .Sp
492 OptiPerl is a Windows IDE with simulated CGI environment, including
493 debugger and syntax\-highlighting editor.
494 .IP Padre 4
495 .IX Item "Padre"
496 <http://padre.perlide.org/>
497 .Sp
498 Padre is cross\-platform IDE for Perl written in Perl using wxWidgets to provide
499 a native look and feel. It\*(Aqs open source under the Artistic License. It
500 is one of the newer Perl IDEs.
501 .IP PerlBuilder 4
502 .IX Item "PerlBuilder"
503 <http://www.solutionsoft.com/perl.htm>
504 .Sp
505 PerlBuilder is an integrated development environment for Windows that
506 supports Perl development.
507 .IP visiPerl+ 4
508 .IX Item "visiPerl+"
509 <http://helpconsulting.net/visiperl/index.html>
510 .Sp
511 From Help Consulting, for Windows.
512 .IP "Visual Perl" 4
513 .IX Item "Visual Perl"
514 <http://www.activestate.com/Products/Visual_Perl/>
515 .Sp
516 Visual Perl is a Visual Studio.NET plug\-in from ActiveState.
517 .IP Zeus 4
518 .IX Item "Zeus"
519 <http://www.zeusedit.com/lookmain.html>
520 .Sp
521 Zeus for Windows is another Win32 multi\-language editor/IDE
522 that comes with support for Perl.
523 .PP
524 For editors: if you\*(Aqre on Unix you probably have vi or a vi clone
525 already, and possibly an emacs too, so you may not need to download
526 anything. In any emacs the cperl\-mode (M\-x cperl\-mode) gives you
527 perhaps the best available Perl editing mode in any editor.
528 .PP
529 If you are using Windows, you can use any editor that lets you work
530 with plain text, such as NotePad or WordPad. Word processors, such as
531 Microsoft Word or WordPerfect, typically do not work since they insert
532 all sorts of behind\-the\-scenes information, although some allow you to
533 save files as "Text Only". You can also download text editors designed
534 specifically for programming, such as Textpad (
535 <http://www.textpad.com/> ) and UltraEdit ( <http://www.ultraedit.com/> ),
536 among others.
537 .PP
538 If you are using MacOS, the same concerns apply. MacPerl (for Classic
539 environments) comes with a simple editor. Popular external editors are
540 BBEdit ( <http://www.barebones.com/products/bbedit/> ) or Alpha (
541 <http://www.his.com/~jguyer/Alpha/Alpha8.html> ). MacOS X users can use
542 Unix editors as well.
543 .IP "GNU Emacs" 4
544 .IX Item "GNU Emacs"
545 <http://www.gnu.org/software/emacs/windows/ntemacs.html>
546 .IP MicroEMACS 4
547 .IX Item "MicroEMACS"
548 <http://www.microemacs.de/>
549 .IP XEmacs 4
550 .IX Item "XEmacs"
551 <http://www.xemacs.org/Download/index.html>
552 .IP Jed 4
553 .IX Item "Jed"
554 <http://space.mit.edu/~davis/jed/>
555 .PP
556 or a vi clone such as
557 .IP Vim 4
558 .IX Item "Vim"
559 <http://www.vim.org/>
560 .IP Vile 4
561 .IX Item "Vile"
562 <http://invisible\-island.net/vile/vile.html>
563 .PP
564 The following are Win32 multilanguage editor/IDEs that support Perl:
565 .IP MultiEdit 4
566 .IX Item "MultiEdit"
567 <http://www.MultiEdit.com/>
568 .IP SlickEdit 4
569 .IX Item "SlickEdit"
570 <http://www.slickedit.com/>
571 .IP ConTEXT 4
572 .IX Item "ConTEXT"
573 <http://www.contexteditor.org/>
574 .PP
575 There is also a toyedit Text widget based editor written in Perl
576 that is distributed with the Tk module on CPAN. The ptkdb
577 ( <http://ptkdb.sourceforge.net/> ) is a Perl/Tk\-based debugger that
578 acts as a development environment of sorts. Perl Composer
579 ( <http://perlcomposer.sourceforge.net/> ) is an IDE for Perl/Tk
580 GUI creation.
581 .PP
582 In addition to an editor/IDE you might be interested in a more
583 powerful shell environment for Win32. Your options include
584 .IP bash 4
585 .IX Item "bash"
586 from the Cygwin package ( <http://cygwin.com/> )
587 .IP zsh 4
588 .IX Item "zsh"
589 <http://www.zsh.org/>
590 .PP
591 Cygwin is covered by the GNU General Public
592 License (but that shouldn\*(Aqt matter for Perl use). Cygwin
593 contains (in addition to the shell) a comprehensive set
594 of standard Unix toolkit utilities.
595 .IP "BBEdit and TextWrangler" 4
596 .IX Item "BBEdit and TextWrangler"
597 are text editors for OS X that have a Perl sensitivity mode
598 ( <http://www.barebones.com/> ).
599 .SS "Where can I get Perl macros for vi?"
600 .IX Subsection "Where can I get Perl macros for vi?"
601 For a complete version of Tom Christiansen\*(Aqs vi configuration file,
602 see <http://www.cpan.org/authors/id/T/TO/TOMC/scripts/toms.exrc.gz> ,
603 the standard benchmark file for vi emulators. The file runs best with nvi,
604 the current version of vi out of Berkeley, which incidentally can be built
605 with an embedded Perl interpreter\-\-see <http://www.cpan.org/src/misc/> .
606 .SS "Where can I get perl\-mode or cperl\-mode for emacs?"
607 .IX Xref "emacs"
608 .IX Subsection "Where can I get perl-mode or cperl-mode for emacs?"
609 Since Emacs version 19 patchlevel 22 or so, there have been both a
610 perl\-mode.el and support for the Perl debugger built in. These should
611 come with the standard Emacs 19 distribution.
612 .PP
613 Note that the perl\-mode of emacs will have fits with \f(CW"main\*(Aqfoo"\fR
614 (single quote), and mess up the indentation and highlighting. You
615 are probably using \f(CW"main::foo"\fR in new Perl code anyway, so this
616 shouldn\*(Aqt be an issue.
617 .PP
618 For CPerlMode, see <https://www.emacswiki.org/emacs/CPerlMode>
619 .SS "How can I use curses with Perl?"
620 .IX Subsection "How can I use curses with Perl?"
621 The Curses module from CPAN provides a dynamically loadable object
622 module interface to a curses library. A small demo can be found at the
623 directory <http://www.cpan.org/authors/id/T/TO/TOMC/scripts/rep.gz> ;
624 this program repeats a command and updates the screen as needed, rendering
625 \&\fBrep ps axu\fR similar to \fBtop\fR.
626 .SS "How can I write a GUI (X, Tk, Gtk, etc.) in Perl?"
627 .IX Xref "GUI Tk Wx WxWidgets Gtk Gtk2 CamelBones Qt"
628 .IX Subsection "How can I write a GUI (X, Tk, Gtk, etc.) in Perl?"
629 (contributed by Ben Morrow)
630 .PP
631 There are a number of modules which let you write GUIs in Perl. Most
632 GUI toolkits have a perl interface: an incomplete list follows.
633 .IP Tk 4
634 .IX Item "Tk"
635 This works under Unix and Windows, and the current version doesn\*(Aqt
636 look half as bad under Windows as it used to. Some of the gui elements
637 still don\*(Aqt \*(Aqfeel\*(Aq quite right, though. The interface is very natural
638 and \*(Aqperlish\*(Aq, making it easy to use in small scripts that just need a
639 simple gui. It hasn\*(Aqt been updated in a while.
640 .IP Wx 4
641 .IX Item "Wx"
642 This is a Perl binding for the cross\-platform wxWidgets toolkit
643 ( <http://www.wxwidgets.org> ). It works under Unix, Win32 and Mac OS X,
644 using native widgets (Gtk under Unix). The interface follows the C++
645 interface closely, but the documentation is a little sparse for someone
646 who doesn\*(Aqt know the library, mostly just referring you to the C++
647 documentation.
648 .IP "Gtk and Gtk2" 4
649 .IX Item "Gtk and Gtk2"
650 These are Perl bindings for the Gtk toolkit ( <http://www.gtk.org> ). The
651 interface changed significantly between versions 1 and 2 so they have
652 separate Perl modules. It runs under Unix, Win32 and Mac OS X (currently
653 it requires an X server on Mac OS, but a \*(Aqnative\*(Aq port is underway), and
654 the widgets look the same on every platform: i.e., they don\*(Aqt match the
655 native widgets. As with Wx, the Perl bindings follow the C API closely,
656 and the documentation requires you to read the C documentation to
657 understand it.
658 .IP Win32::GUI 4
659 .IX Item "Win32::GUI"
660 This provides access to most of the Win32 GUI widgets from Perl.
661 Obviously, it only runs under Win32, and uses native widgets. The Perl
662 interface doesn\*(Aqt really follow the C interface: it\*(Aqs been made more
663 Perlish, and the documentation is pretty good. More advanced stuff may
664 require familiarity with the C Win32 APIs, or reference to MSDN.
665 .IP CamelBones 4
666 .IX Item "CamelBones"
667 CamelBones ( <http://camelbones.sourceforge.net> ) is a Perl interface to
668 Mac OS X\*(Aqs Cocoa GUI toolkit, and as such can be used to produce native
669 GUIs on Mac OS X. It\*(Aqs not on CPAN, as it requires frameworks that
670 CPAN.pm doesn\*(Aqt know how to install, but installation is via the
671 standard OSX package installer. The Perl API is, again, very close to
672 the ObjC API it\*(Aqs wrapping, and the documentation just tells you how to
673 translate from one to the other.
674 .IP Qt 4
675 .IX Item "Qt"
676 There is a Perl interface to TrollTech\*(Aqs Qt toolkit, but it does not
677 appear to be maintained.
678 .IP Athena 4
679 .IX Item "Athena"
680 Sx is an interface to the Athena widget set which comes with X, but
681 again it appears not to be much used nowadays.
682 .SS "How can I make my Perl program run faster?"
683 .IX Subsection "How can I make my Perl program run faster?"
684 The best way to do this is to come up with a better algorithm. This
685 can often make a dramatic difference. Jon Bentley\*(Aqs book
686 \&\fIProgramming Pearls\fR (that\*(Aqs not a misspelling!) has some good tips
687 on optimization, too. Advice on benchmarking boils down to: benchmark
688 and profile to make sure you\*(Aqre optimizing the right part, look for
689 better algorithms instead of microtuning your code, and when all else
690 fails consider just buying faster hardware. You will probably want to
691 read the answer to the earlier question "How do I profile my Perl
692 programs?" if you haven\*(Aqt done so already.
693 .PP
694 A different approach is to autoload seldom\-used Perl code. See the
695 AutoSplit and AutoLoader modules in the standard distribution for
696 that. Or you could locate the bottleneck and think about writing just
697 that part in C, the way we used to take bottlenecks in C code and
698 write them in assembler. Similar to rewriting in C, modules that have
699 critical sections can be written in C (for instance, the PDL module
700 from CPAN).
701 .PP
702 If you\*(Aqre currently linking your perl executable to a shared
703 \&\fIlibc.so\fR, you can often gain a 10\-25% performance benefit by
704 rebuilding it to link with a static libc.a instead. This will make a
705 bigger perl executable, but your Perl programs (and programmers) may
706 thank you for it. See the \fIINSTALL\fR file in the source distribution
707 for more information.
708 .PP
709 The undump program was an ancient attempt to speed up Perl program by
710 storing the already\-compiled form to disk. This is no longer a viable
711 option, as it only worked on a few architectures, and wasn\*(Aqt a good
712 solution anyway.
713 .SS "How can I make my Perl program take less memory?"
714 .IX Subsection "How can I make my Perl program take less memory?"
715 When it comes to time\-space tradeoffs, Perl nearly always prefers to
716 throw memory at a problem. Scalars in Perl use more memory than
717 strings in C, arrays take more than that, and hashes use even more. While
718 there\*(Aqs still a lot to be done, recent releases have been addressing
719 these issues. For example, as of 5.004, duplicate hash keys are
720 shared amongst all hashes using them, so require no reallocation.
721 .PP
722 In some cases, using \fBsubstr()\fR or \fBvec()\fR to simulate arrays can be
723 highly beneficial. For example, an array of a thousand booleans will
724 take at least 20,000 bytes of space, but it can be turned into one
725 125\-byte bit vector\-\-a considerable memory savings. The standard
726 Tie::SubstrHash module can also help for certain types of data
727 structure. If you\*(Aqre working with specialist data structures
728 (matrices, for instance) modules that implement these in C may use
729 less memory than equivalent Perl modules.
730 .PP
731 Another thing to try is learning whether your Perl was compiled with
732 the system malloc or with Perl\*(Aqs builtin malloc. Whichever one it
733 is, try using the other one and see whether this makes a difference.
734 Information about malloc is in the \fIINSTALL\fR file in the source
735 distribution. You can find out whether you are using perl\*(Aqs malloc by
736 typing \f(CW\*(C`perl \-V:usemymalloc\*(C'\fR.
737 .PP
738 Of course, the best way to save memory is to not do anything to waste
739 it in the first place. Good programming practices can go a long way
740 toward this:
741 .IP "Don\*(Aqt slurp!" 4
742 .IX Item "Don't slurp!"
743 Don\*(Aqt read an entire file into memory if you can process it line
744 by line. Or more concretely, use a loop like this:
745 .Sp
746 .Vb 6
747 \& #
748 \& # Good Idea
749 \& #
750 \& while (my $line = <$file_handle>) {
751 \& # ...
752 \& }
753 .Ve
754 .Sp
755 instead of this:
756 .Sp
757 .Vb 7
758 \& #
759 \& # Bad Idea
760 \& #
761 \& my @data = <$file_handle>;
762 \& foreach (@data) {
763 \& # ...
764 \& }
765 .Ve
766 .Sp
767 When the files you\*(Aqre processing are small, it doesn\*(Aqt much matter which
768 way you do it, but it makes a huge difference when they start getting
769 larger.
770 .IP "Use map and grep selectively" 4
771 .IX Item "Use map and grep selectively"
772 Remember that both map and grep expect a LIST argument, so doing this:
773 .Sp
774 .Vb 1
775 \& @wanted = grep {/pattern/} <$file_handle>;
776 .Ve
777 .Sp
778 will cause the entire file to be slurped. For large files, it\*(Aqs better
779 to loop:
780 .Sp
781 .Vb 3
782 \& while (<$file_handle>) {
783 \& push(@wanted, $_) if /pattern/;
784 \& }
785 .Ve
786 .IP "Avoid unnecessary quotes and stringification" 4
787 .IX Item "Avoid unnecessary quotes and stringification"
788 Don\*(Aqt quote large strings unless absolutely necessary:
789 .Sp
790 .Vb 1
791 \& my $copy = "$large_string";
792 .Ve
793 .Sp
794 makes 2 copies of \f(CW$large_string\fR (one for \f(CW$copy\fR and another for the
795 quotes), whereas
796 .Sp
797 .Vb 1
798 \& my $copy = $large_string;
799 .Ve
800 .Sp
801 only makes one copy.
802 .Sp
803 Ditto for stringifying large arrays:
804 .Sp
805 .Vb 4
806 \& {
807 \& local $, = "\en";
808 \& print @big_array;
809 \& }
810 .Ve
811 .Sp
812 is much more memory\-efficient than either
813 .Sp
814 .Vb 1
815 \& print join "\en", @big_array;
816 .Ve
817 .Sp
818 or
819 .Sp
820 .Vb 4
821 \& {
822 \& local $" = "\en";
823 \& print "@big_array";
824 \& }
825 .Ve
826 .IP "Pass by reference" 4
827 .IX Item "Pass by reference"
828 Pass arrays and hashes by reference, not by value. For one thing, it\*(Aqs
829 the only way to pass multiple lists or hashes (or both) in a single
830 call/return. It also avoids creating a copy of all the contents. This
831 requires some judgement, however, because any changes will be propagated
832 back to the original data. If you really want to mangle (er, modify) a
833 copy, you\*(Aqll have to sacrifice the memory needed to make one.
834 .IP "Tie large variables to disk" 4
835 .IX Item "Tie large variables to disk"
836 For "big" data stores (i.e. ones that exceed available memory) consider
837 using one of the DB modules to store it on disk instead of in RAM. This
838 will incur a penalty in access time, but that\*(Aqs probably better than
839 causing your hard disk to thrash due to massive swapping.
840 .SS "Is it safe to return a reference to local or lexical data?"
841 .IX Subsection "Is it safe to return a reference to local or lexical data?"
842 Yes. Perl\*(Aqs garbage collection system takes care of this so
843 everything works out right.
844 .PP
845 .Vb 4
846 \& sub makeone {
847 \& my @a = ( 1 .. 10 );
848 \& return \e@a;
849 \& }
850 \&
851 \& for ( 1 .. 10 ) {
852 \& push @many, makeone();
853 \& }
854 \&
855 \& print $many[4][5], "\en";
856 \&
857 \& print "@many\en";
858 .Ve
859 .SS "How can I free an array or hash so my program shrinks?"
860 .IX Subsection "How can I free an array or hash so my program shrinks?"
861 (contributed by Michael Carman)
862 .PP
863 You usually can\*(Aqt. Memory allocated to lexicals (i.e. \fBmy()\fR variables)
864 cannot be reclaimed or reused even if they go out of scope. It is
865 reserved in case the variables come back into scope. Memory allocated
866 to global variables can be reused (within your program) by using
867 \&\fBundef()\fR and/or \fBdelete()\fR.
868 .PP
869 On most operating systems, memory allocated to a program can never be
870 returned to the system. That\*(Aqs why long\-running programs sometimes re\-
871 exec themselves. Some operating systems (notably, systems that use
872 \&\fBmmap\fR\|(2) for allocating large chunks of memory) can reclaim memory that
873 is no longer used, but on such systems, perl must be configured and
874 compiled to use the OS\*(Aqs malloc, not perl\*(Aqs.
875 .PP
876 In general, memory allocation and de\-allocation isn\*(Aqt something you can
877 or should be worrying about much in Perl.
878 .PP
879 See also "How can I make my Perl program take less memory?"
880 .SS "How can I make my CGI script more efficient?"
881 .IX Subsection "How can I make my CGI script more efficient?"
882 Beyond the normal measures described to make general Perl programs
883 faster or smaller, a CGI program has additional issues. It may be run
884 several times per second. Given that each time it runs it will need
885 to be re\-compiled and will often allocate a megabyte or more of system
886 memory, this can be a killer. Compiling into C \fBisn\*(Aqt going to help
887 you\fR because the process start\-up overhead is where the bottleneck is.
888 .PP
889 There are three popular ways to avoid this overhead. One solution
890 involves running the Apache HTTP server (available from
891 <http://www.apache.org/> ) with either of the mod_perl or mod_fastcgi
892 plugin modules.
893 .PP
894 With mod_perl and the Apache::Registry module (distributed with
895 mod_perl), httpd will run with an embedded Perl interpreter which
896 pre\-compiles your script and then executes it within the same address
897 space without forking. The Apache extension also gives Perl access to
898 the internal server API, so modules written in Perl can do just about
899 anything a module written in C can. For more on mod_perl, see
900 <http://perl.apache.org/>
901 .PP
902 With the FCGI module (from CPAN) and the mod_fastcgi
903 module (available from <http://www.fastcgi.com/> ) each of your Perl
904 programs becomes a permanent CGI daemon process.
905 .PP
906 Finally, Plack is a Perl module and toolkit that contains PSGI middleware,
907 helpers and adapters to web servers, allowing you to easily deploy scripts which
908 can continue running, and provides flexibility with regards to which web server
909 you use. It can allow existing CGI scripts to enjoy this flexibility and
910 performance with minimal changes, or can be used along with modern Perl web
911 frameworks to make writing and deploying web services with Perl a breeze.
912 .PP
913 These solutions can have far\-reaching effects on your system and on the way you
914 write your CGI programs, so investigate them with care.
915 .PP
916 See also
917 <http://www.cpan.org/modules/by\-category/15_World_Wide_Web_HTML_HTTP_CGI/> .
918 .SS "How can I hide the source for my Perl program?"
919 .IX Subsection "How can I hide the source for my Perl program?"
920 Delete it. :\-) Seriously, there are a number of (mostly
921 unsatisfactory) solutions with varying levels of "security".
922 .PP
923 First of all, however, you \fIcan\*(Aqt\fR take away read permission, because
924 the source code has to be readable in order to be compiled and
925 interpreted. (That doesn\*(Aqt mean that a CGI script\*(Aqs source is
926 readable by people on the web, though\-\-only by people with access to
927 the filesystem.) So you have to leave the permissions at the socially
928 friendly 0755 level.
929 .PP
930 Some people regard this as a security problem. If your program does
931 insecure things and relies on people not knowing how to exploit those
932 insecurities, it is not secure. It is often possible for someone to
933 determine the insecure things and exploit them without viewing the
934 source. Security through obscurity, the name for hiding your bugs
935 instead of fixing them, is little security indeed.
936 .PP
937 You can try using encryption via source filters (Starting from Perl
938 5.8 the Filter::Simple and Filter::Util::Call modules are included in
939 the standard distribution), but any decent programmer will be able to
940 decrypt it. You can try using the byte code compiler and interpreter
941 described later in perlfaq3, but the curious might still be able to
942 de\-compile it. You can try using the native\-code compiler described
943 later, but crackers might be able to disassemble it. These pose
944 varying degrees of difficulty to people wanting to get at your code,
945 but none can definitively conceal it (true of every language, not just
946 Perl).
947 .PP
948 It is very easy to recover the source of Perl programs. You simply
949 feed the program to the perl interpreter and use the modules in
950 the B:: hierarchy. The B::Deparse module should be able to
951 defeat most attempts to hide source. Again, this is not
952 unique to Perl.
953 .PP
954 If you\*(Aqre concerned about people profiting from your code, then the
955 bottom line is that nothing but a restrictive license will give you
956 legal security. License your software and pepper it with threatening
957 statements like "This is unpublished proprietary software of XYZ Corp.
958 Your access to it does not give you permission to use it blah blah
959 blah." We are not lawyers, of course, so you should see a lawyer if
960 you want to be sure your license\*(Aqs wording will stand up in court.
961 .SS "How can I compile my Perl program into byte code or C?"
962 .IX Subsection "How can I compile my Perl program into byte code or C?"
963 (contributed by brian d foy)
964 .PP
965 In general, you can\*(Aqt do this. There are some things that may work
966 for your situation though. People usually ask this question
967 because they want to distribute their works without giving away
968 the source code, and most solutions trade disk space for convenience.
969 You probably won\*(Aqt see much of a speed increase either, since most
970 solutions simply bundle a Perl interpreter in the final product
971 (but see "How can I make my Perl program run faster?").
972 .PP
973 The Perl Archive Toolkit is Perl\*(Aqs analog to Java\*(Aqs JAR. It\*(Aqs freely
974 available and on CPAN ( <https://metacpan.org/pod/PAR> ).
975 .PP
976 There are also some commercial products that may work for you, although
977 you have to buy a license for them.
978 .PP
979 The Perl Dev Kit ( <http://www.activestate.com/Products/Perl_Dev_Kit/> )
980 from ActiveState can "Turn your Perl programs into ready\-to\-run
981 executables for HP\-UX, Linux, Solaris and Windows."
982 .PP
983 Perl2Exe ( <http://www.indigostar.com/perl2exe.htm> ) is a command line
984 program for converting perl scripts to executable files. It targets both
985 Windows and Unix platforms.
986 .ie n .SS "How can I get ""#!perl"" to work on [MS\-DOS,NT,...]?"
987 .el .SS "How can I get \f(CW#!perl\fP to work on [MS\-DOS,NT,...]?"
988 .IX Subsection "How can I get #!perl to work on [MS-DOS,NT,...]?"
989 For OS/2 just use
990 .PP
991 .Vb 1
992 \& extproc perl \-S \-your_switches
993 .Ve
994 .PP
995 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\*(Aqs
996 "extproc" handling). For DOS one should first invent a corresponding
997 batch file and codify it in \f(CW\*(C`ALTERNATE_SHEBANG\*(C'\fR (see the
998 \&\fIdosish.h\fR file in the source distribution for more information).
999 .PP
1000 The Win95/NT installation, when using the ActiveState port of Perl,
1001 will modify the Registry to associate the \f(CW\*(C`.pl\*(C'\fR extension with the
1002 perl interpreter. If you install another port, perhaps even building
1003 your own Win95/NT Perl from the standard sources by using a Windows port
1004 of gcc (e.g., with cygwin or mingw32), then you\*(Aqll have to modify
1005 the Registry yourself. In addition to associating \f(CW\*(C`.pl\*(C'\fR with the
1006 interpreter, NT people can use: \f(CW\*(C`SET PATHEXT=%PATHEXT%;.PL\*(C'\fR to let them
1007 run the program \f(CW\*(C`install\-linux.pl\*(C'\fR merely by typing \f(CW\*(C`install\-linux\*(C'\fR.
1008 .PP
1009 Under "Classic" MacOS, a perl program will have the appropriate Creator and
1010 Type, so that double\-clicking them will invoke the MacPerl application.
1011 Under Mac OS X, clickable apps can be made from any \f(CW\*(C`#!\*(C'\fR script using Wil
1012 Sanchez\*(Aq DropScript utility: <http://www.wsanchez.net/software/> .
1013 .PP
1014 \&\fIIMPORTANT!\fR: Whatever you do, PLEASE don\*(Aqt get frustrated, and just
1015 throw the perl interpreter into your cgi\-bin directory, in order to
1016 get your programs working for a web server. This is an EXTREMELY big
1017 security risk. Take the time to figure out how to do it correctly.
1018 .SS "Can I write useful Perl programs on the command line?"
1019 .IX Subsection "Can I write useful Perl programs on the command line?"
1020 Yes. Read perlrun for more information. Some examples follow.
1021 (These assume standard Unix shell quoting rules.)
1022 .PP
1023 .Vb 2
1024 \& # sum first and last fields
1025 \& perl \-lane \*(Aqprint $F[0] + $F[\-1]\*(Aq *
1026 \&
1027 \& # identify text files
1028 \& perl \-le \*(Aqfor(@ARGV) {print if \-f && \-T _}\*(Aq *
1029 \&
1030 \& # remove (most) comments from C program
1031 \& perl \-0777 \-pe \*(Aqs{/\e*.*?\e*/}{}gs\*(Aq foo.c
1032 \&
1033 \& # make file a month younger than today, defeating reaper daemons
1034 \& perl \-e \*(Aq$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)\*(Aq *
1035 \&
1036 \& # find first unused uid
1037 \& perl \-le \*(Aq$i++ while getpwuid($i); print $i\*(Aq
1038 \&
1039 \& # display reasonable manpath
1040 \& echo $PATH | perl \-nl \-072 \-e \*(Aq
1041 \& s![^/+]*$!man!&&\-d&&!$s{$_}++&&push@m,$_;END{print"@m"}\*(Aq
1042 .Ve
1043 .PP
1044 OK, the last one was actually an Obfuscated Perl Contest entry. :\-)
1045 .SS "Why don\*(Aqt Perl one\-liners work on my DOS/Mac/VMS system?"
1046 .IX Subsection "Why don't Perl one-liners work on my DOS/Mac/VMS system?"
1047 The problem is usually that the command interpreters on those systems
1048 have rather different ideas about quoting than the Unix shells under
1049 which the one\-liners were created. On some systems, you may have to
1050 change single\-quotes to double ones, which you must \fINOT\fR do on Unix
1051 or Plan9 systems. You might also have to change a single % to a %%.
1052 .PP
1053 For example:
1054 .PP
1055 .Vb 2
1056 \& # Unix (including Mac OS X)
1057 \& perl \-e \*(Aqprint "Hello world\en"\*(Aq
1058 \&
1059 \& # DOS, etc.
1060 \& perl \-e "print \e"Hello world\en\e""
1061 \&
1062 \& # Mac Classic
1063 \& print "Hello world\en"
1064 \& (then Run "Myscript" or Shift\-Command\-R)
1065 \&
1066 \& # MPW
1067 \& perl \-e \*(Aqprint "Hello world\en"\*(Aq
1068 \&
1069 \& # VMS
1070 \& perl \-e "print ""Hello world\en"""
1071 .Ve
1072 .PP
1073 The problem is that none of these examples are reliable: they depend on the
1074 command interpreter. Under Unix, the first two often work. Under DOS,
1075 it\*(Aqs entirely possible that neither works. If 4DOS was the command shell,
1076 you\*(Aqd probably have better luck like this:
1077 .PP
1078 .Vb 1
1079 \& perl \-e "print <Ctrl\-x>"Hello world\en<Ctrl\-x>""
1080 .Ve
1081 .PP
1082 Under the Mac, it depends which environment you are using. The MacPerl
1083 shell, or MPW, is much like Unix shells in its support for several
1084 quoting variants, except that it makes free use of the Mac\*(Aqs non\-ASCII
1085 characters as control characters.
1086 .PP
1087 Using \fBqq()\fR, q(), and \fBqx()\fR, instead of "double quotes", \*(Aqsingle
1088 quotes\*(Aq, and \`backticks\`, may make one\-liners easier to write.
1089 .PP
1090 There is no general solution to all of this. It is a mess.
1091 .PP
1092 [Some of this answer was contributed by Kenneth Albanowski.]
1093 .SS "Where can I learn about CGI or Web programming in Perl?"
1094 .IX Subsection "Where can I learn about CGI or Web programming in Perl?"
1095 For modules, get the CGI or LWP modules from CPAN. For textbooks,
1096 see the two especially dedicated to web stuff in the question on
1097 books. For problems and questions related to the web, like "Why
1098 do I get 500 Errors" or "Why doesn\*(Aqt it run from the browser right
1099 when it runs fine on the command line", see the troubleshooting
1100 guides and references in perlfaq9 or in the CGI MetaFAQ:
1101 .PP
1102 .Vb 1
1103 \& L<http://www.perl.org/CGI_MetaFAQ.html>
1104 .Ve
1105 .PP
1106 Looking into <https://plackperl.org> and modern Perl web frameworks is highly recommended,
1107 though; web programming in Perl has evolved a long way from the old days of
1108 simple CGI scripts.
1109 .SS "Where can I learn about object\-oriented Perl programming?"
1110 .IX Subsection "Where can I learn about object-oriented Perl programming?"
1111 A good place to start is perlootut, and you can use perlobj for
1112 reference.
1113 .PP
1114 A good book on OO on Perl is the "Object\-Oriented Perl"
1115 by Damian Conway from Manning Publications, or "Intermediate Perl"
1116 by Randal Schwartz, brian d foy, and Tom Phoenix from O\*(AqReilly Media.
1117 .SS "Where can I learn about linking C with Perl?"
1118 .IX Subsection "Where can I learn about linking C with Perl?"
1119 If you want to call C from Perl, start with perlxstut,
1120 moving on to perlxs, xsubpp, and perlguts. If you want to
1121 call Perl from C, then read perlembed, perlcall, and
1122 perlguts. Don\*(Aqt forget that you can learn a lot from looking at
1123 how the authors of existing extension modules wrote their code and
1124 solved their problems.
1125 .PP
1126 You might not need all the power of XS. The Inline::C module lets
1127 you put C code directly in your Perl source. It handles all the
1128 magic to make it work. You still have to learn at least some of
1129 the perl API but you won\*(Aqt have to deal with the complexity of the
1130 XS support files.
1131 .SS "I\*(Aqve read perlembed, perlguts, etc., but I can\*(Aqt embed perl in my C program; what am I doing wrong?"
1132 .IX Subsection "I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong?"
1133 Download the ExtUtils::Embed kit from CPAN and run \`make test\*(Aq. If
1134 the tests pass, read the pods again and again and again. If they
1135 fail, submit a bug report to <https://github.com/Perl/perl5/issues>
1136 with the output of
1137 \&\f(CW\*(C`make test TEST_VERBOSE=1\*(C'\fR along with \f(CW\*(C`perl \-V\*(C'\fR.
1138 .SS "When I tried to run my script, I got this message. What does it mean?"
1139 .IX Subsection "When I tried to run my script, I got this message. What does it mean?"
1140 A complete list of Perl\*(Aqs error messages and warnings with explanatory
1141 text can be found in perldiag. You can also use the splain program
1142 (distributed with Perl) to explain the error messages:
1143 .PP
1144 .Vb 2
1145 \& perl program 2>diag.out
1146 \& splain [\-v] [\-p] diag.out
1147 .Ve
1148 .PP
1149 or change your program to explain the messages for you:
1150 .PP
1151 .Vb 1
1152 \& use diagnostics;
1153 .Ve
1154 .PP
1155 or
1156 .PP
1157 .Vb 1
1158 \& use diagnostics \-verbose;
1159 .Ve
1160 .SS "What\*(Aqs MakeMaker?"
1161 .IX Subsection "What's MakeMaker?"
1162 (contributed by brian d foy)
1163 .PP
1164 The ExtUtils::MakeMaker module, better known simply as "MakeMaker",
1165 turns a Perl script, typically called \f(CW\*(C`Makefile.PL\*(C'\fR, into a Makefile.
1166 The Unix tool \f(CW\*(C`make\*(C'\fR uses this file to manage dependencies and actions
1167 to process and install a Perl distribution.
1168 .SH "AUTHOR AND COPYRIGHT"
1169 .IX Header "AUTHOR AND COPYRIGHT"
1170 Copyright (c) 1997\-2010 Tom Christiansen, Nathan Torkington, and
1171 other authors as noted. All rights reserved.
1172 .PP
1173 This documentation is free; you can redistribute it and/or modify it
1174 under the same terms as Perl itself.
1175 .PP
1176 Irrespective of its distribution, all code examples here are in the public
1177 domain. You are permitted and encouraged to use this code and any
1178 derivatives thereof in your own programs for fun or for profit as you
1179 see fit. A simple comment in the code giving credit to the FAQ would
1180 be courteous but is not required.