Debian Codegraph @

upstream/debian-unstable/man1/perlfaq3.1

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