Debian Codegraph @

upstream/mageia-cauldron/man1/perlfaq.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 "PERLFAQ 1"
61 .TH PERLFAQ 1 2025-06-24 "perl v5.42.0" "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 perlfaq \- Frequently asked questions about Perl
68 .SH VERSION
69 .IX Header "VERSION"
70 version 5.20250619
71 .SH DESCRIPTION
72 .IX Header "DESCRIPTION"
73 The perlfaq comprises several documents that answer the most commonly
74 asked questions about Perl and Perl programming. It\*(Aqs divided by topic
75 into nine major sections outlined in this document.
76 .SS "Where to find the perlfaq"
77 .IX Subsection "Where to find the perlfaq"
78 The perlfaq is an evolving document. Read the latest version at
79 <https://perldoc.perl.org/perlfaq>. It is also included in the standard Perl
80 distribution.
81 .SS "How to use the perlfaq"
82 .IX Subsection "How to use the perlfaq"
83 The \f(CW\*(C`perldoc\*(C'\fR command line tool is part of the standard Perl distribution. To
84 read the perlfaq:
85 .PP
86 .Vb 1
87 \& $ perldoc perlfaq
88 .Ve
89 .PP
90 To search the perlfaq question headings:
91 .PP
92 .Vb 1
93 \& $ perldoc \-q open
94 .Ve
95 .SS "How to contribute to the perlfaq"
96 .IX Subsection "How to contribute to the perlfaq"
97 Review <https://github.com/perl\-doc\-cats/perlfaq/wiki>. If you don\*(Aqt find
98 your suggestion create an issue or pull request against
99 <https://github.com/perl\-doc\-cats/perlfaq>.
100 .PP
101 Once approved, changes will be distributed with the next Perl release and
102 subsequently appear at <https://perldoc.perl.org/perlfaq>.
103 .SS "What if my question isn\*(Aqt answered in the FAQ?"
104 .IX Subsection "What if my question isn't answered in the FAQ?"
105 Try the resources in perlfaq2.
106 .SH "TABLE OF CONTENTS"
107 .IX Header "TABLE OF CONTENTS"
108 .IP "perlfaq1 \- General Questions About Perl" 4
109 .IX Item "perlfaq1 - General Questions About Perl"
110 .PD 0
111 .IP "perlfaq2 \- Obtaining and Learning about Perl" 4
112 .IX Item "perlfaq2 - Obtaining and Learning about Perl"
113 .IP "perlfaq3 \- Programming Tools" 4
114 .IX Item "perlfaq3 - Programming Tools"
115 .IP "perlfaq4 \- Data Manipulation" 4
116 .IX Item "perlfaq4 - Data Manipulation"
117 .IP "perlfaq5 \- Files and Formats" 4
118 .IX Item "perlfaq5 - Files and Formats"
119 .IP "perlfaq6 \- Regular Expressions" 4
120 .IX Item "perlfaq6 - Regular Expressions"
121 .IP "perlfaq7 \- General Perl Language Issues" 4
122 .IX Item "perlfaq7 - General Perl Language Issues"
123 .IP "perlfaq8 \- System Interaction" 4
124 .IX Item "perlfaq8 - System Interaction"
125 .IP "perlfaq9 \- Web, Email and Networking" 4
126 .IX Item "perlfaq9 - Web, Email and Networking"
127 .PD
128 .SH "THE QUESTIONS"
129 .IX Header "THE QUESTIONS"
130 .SS "perlfaq1: General Questions About Perl"
131 .IX Subsection "perlfaq1: General Questions About Perl"
132 This section of the FAQ answers very general, high\-level questions about Perl.
133 .IP \(bu 4
134 What is Perl?
135 .IP \(bu 4
136 Who supports Perl? Who develops it? Why is it free?
137 .IP \(bu 4
138 Which version of Perl should I use?
139 .IP \(bu 4
140 What is Raku (Perl 6)?
141 .IP \(bu 4
142 How stable is Perl?
143 .IP \(bu 4
144 How often are new versions of Perl released?
145 .IP \(bu 4
146 Is Perl difficult to learn?
147 .IP \(bu 4
148 How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl?
149 .IP \(bu 4
150 Can I do [task] in Perl?
151 .IP \(bu 4
152 When shouldn\*(Aqt I program in Perl?
153 .IP \(bu 4
154 What\*(Aqs the difference between "perl" and "Perl"?
155 .IP \(bu 4
156 What is a JAPH?
157 .IP \(bu 4
158 How can I convince others to use Perl?
159 .SS "perlfaq2: Obtaining and Learning about Perl"
160 .IX Subsection "perlfaq2: Obtaining and Learning about Perl"
161 This section of the FAQ answers questions about where to find source and documentation for Perl, support, and related matters.
162 .IP \(bu 4
163 What machines support Perl? Where do I get it?
164 .IP \(bu 4
165 How can I get a binary version of Perl?
166 .IP \(bu 4
167 I don\*(Aqt have a C compiler. How can I build my own Perl interpreter?
168 .IP \(bu 4
169 I copied the Perl binary from one machine to another, but scripts don\*(Aqt work.
170 .IP \(bu 4
171 I grabbed the sources and tried to compile but gdbm/dynamic loading/malloc/linking/... failed. How do I make it work?
172 .IP \(bu 4
173 What modules and extensions are available for Perl? What is CPAN?
174 .IP \(bu 4
175 Where can I get information on Perl?
176 .IP \(bu 4
177 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org?
178 .IP \(bu 4
179 Where can I post questions?
180 .IP \(bu 4
181 Perl Books
182 .IP \(bu 4
183 Which magazines have Perl content?
184 .IP \(bu 4
185 Which Perl blogs should I read?
186 .IP \(bu 4
187 What mailing lists are there for Perl?
188 .IP \(bu 4
189 Where can I buy a commercial version of Perl?
190 .IP \(bu 4
191 Where do I send bug reports?
192 .SS "perlfaq3: Programming Tools"
193 .IX Subsection "perlfaq3: Programming Tools"
194 This section of the FAQ answers questions related to programmer tools and programming support.
195 .IP \(bu 4
196 How do I do (anything)?
197 .IP \(bu 4
198 How can I use Perl interactively?
199 .IP \(bu 4
200 How do I find which modules are installed on my system?
201 .IP \(bu 4
202 How do I debug my Perl programs?
203 .IP \(bu 4
204 How do I profile my Perl programs?
205 .IP \(bu 4
206 How do I cross\-reference my Perl programs?
207 .IP \(bu 4
208 Is there a pretty\-printer (formatter) for Perl?
209 .IP \(bu 4
210 Is there an IDE or Windows Perl Editor?
211 .IP \(bu 4
212 Where can I get Perl macros for vi?
213 .IP \(bu 4
214 Where can I get perl\-mode or cperl\-mode for emacs?
215 .IP \(bu 4
216 How can I use curses with Perl?
217 .IP \(bu 4
218 How can I write a GUI (X, Tk, Gtk, etc.) in Perl?
219 .IP \(bu 4
220 How can I make my Perl program run faster?
221 .IP \(bu 4
222 How can I make my Perl program take less memory?
223 .IP \(bu 4
224 Is it safe to return a reference to local or lexical data?
225 .IP \(bu 4
226 How can I free an array or hash so my program shrinks?
227 .IP \(bu 4
228 How can I make my CGI script more efficient?
229 .IP \(bu 4
230 How can I hide the source for my Perl program?
231 .IP \(bu 4
232 How can I compile my Perl program into byte code or C?
233 .IP \(bu 4
234 How can I get \f(CW\*(C`#!perl\*(C'\fR to work on [MS\-DOS,NT,...]?
235 .IP \(bu 4
236 Can I write useful Perl programs on the command line?
237 .IP \(bu 4
238 Why don\*(Aqt Perl one\-liners work on my DOS/Mac/VMS system?
239 .IP \(bu 4
240 Where can I learn about CGI or Web programming in Perl?
241 .IP \(bu 4
242 Where can I learn about object\-oriented Perl programming?
243 .IP \(bu 4
244 Where can I learn about linking C with Perl?
245 .IP \(bu 4
246 I\*(Aqve read perlembed, perlguts, etc., but I can\*(Aqt embed perl in my C program; what am I doing wrong?
247 .IP \(bu 4
248 When I tried to run my script, I got this message. What does it mean?
249 .IP \(bu 4
250 What\*(Aqs MakeMaker?
251 .SS "perlfaq4: Data Manipulation"
252 .IX Subsection "perlfaq4: Data Manipulation"
253 This section of the FAQ answers questions related to manipulating numbers, dates, strings, arrays, hashes, and miscellaneous data issues.
254 .IP \(bu 4
255 Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?
256 .IP \(bu 4
257 Why is \fBint()\fR broken?
258 .IP \(bu 4
259 Why isn\*(Aqt my octal data interpreted correctly?
260 .IP \(bu 4
261 Does Perl have a \fBround()\fR function? What about \fBceil()\fR and \fBfloor()\fR? Trig functions?
262 .IP \(bu 4
263 How do I convert between numeric representations/bases/radixes?
264 .IP \(bu 4
265 Why doesn\*(Aqt & work the way I want it to?
266 .IP \(bu 4
267 How do I multiply matrices?
268 .IP \(bu 4
269 How do I perform an operation on a series of integers?
270 .IP \(bu 4
271 How can I output Roman numerals?
272 .IP \(bu 4
273 Why aren\*(Aqt my random numbers random?
274 .IP \(bu 4
275 How do I get a random number between X and Y?
276 .IP \(bu 4
277 How do I find the day or week of the year?
278 .IP \(bu 4
279 How do I find the current century or millennium?
280 .IP \(bu 4
281 How can I compare two dates and find the difference?
282 .IP \(bu 4
283 How can I take a string and turn it into epoch seconds?
284 .IP \(bu 4
285 How can I find the Julian Day?
286 .IP \(bu 4
287 How do I find yesterday\*(Aqs date?
288 .IP \(bu 4
289 Does Perl have a Year 2000 or 2038 problem? Is Perl Y2K compliant?
290 .IP \(bu 4
291 How do I validate input?
292 .IP \(bu 4
293 How do I unescape a string?
294 .IP \(bu 4
295 How do I remove consecutive pairs of characters?
296 .IP \(bu 4
297 How do I expand function calls in a string?
298 .IP \(bu 4
299 How do I find matching/nesting anything?
300 .IP \(bu 4
301 How do I reverse a string?
302 .IP \(bu 4
303 How do I expand tabs in a string?
304 .IP \(bu 4
305 How do I reformat a paragraph?
306 .IP \(bu 4
307 How can I access or change N characters of a string?
308 .IP \(bu 4
309 How do I change the Nth occurrence of something?
310 .IP \(bu 4
311 How can I count the number of occurrences of a substring within a string?
312 .IP \(bu 4
313 How do I capitalize all the words on one line?
314 .IP \(bu 4
315 How can I split a [character]\-delimited string except when inside [character]?
316 .IP \(bu 4
317 How do I strip blank space from the beginning/end of a string?
318 .IP \(bu 4
319 How do I pad a string with blanks or pad a number with zeroes?
320 .IP \(bu 4
321 How do I extract selected columns from a string?
322 .IP \(bu 4
323 How do I find the soundex value of a string?
324 .IP \(bu 4
325 How can I expand variables in text strings?
326 .IP \(bu 4
327 Does Perl have anything like Ruby\*(Aqs #{} or Python\*(Aqs f string?
328 .IP \(bu 4
329 What\*(Aqs wrong with always quoting "$vars"?
330 .IP \(bu 4
331 Why don\*(Aqt my <<HERE documents work?
332 .IP \(bu 4
333 What is the difference between a list and an array?
334 .IP \(bu 4
335 What is the difference between \f(CW$array\fR[1] and \f(CW@array\fR[1]?
336 .IP \(bu 4
337 How can I remove duplicate elements from a list or array?
338 .IP \(bu 4
339 How can I tell whether a certain element is contained in a list or array?
340 .IP \(bu 4
341 How do I compute the difference of two arrays? How do I compute the intersection of two arrays?
342 .IP \(bu 4
343 How do I test whether two arrays or hashes are equal?
344 .IP \(bu 4
345 How do I find the first array element for which a condition is true?
346 .IP \(bu 4
347 How do I handle linked lists?
348 .IP \(bu 4
349 How do I handle circular lists?
350 .IP \(bu 4
351 How do I shuffle an array randomly?
352 .IP \(bu 4
353 How do I process/modify each element of an array?
354 .IP \(bu 4
355 How do I select a random element from an array?
356 .IP \(bu 4
357 How do I permute N elements of a list?
358 .IP \(bu 4
359 How do I sort an array by (anything)?
360 .IP \(bu 4
361 How do I manipulate arrays of bits?
362 .IP \(bu 4
363 Why does \fBdefined()\fR return true on empty arrays and hashes?
364 .IP \(bu 4
365 How do I process an entire hash?
366 .IP \(bu 4
367 How do I merge two hashes?
368 .IP \(bu 4
369 What happens if I add or remove keys from a hash while iterating over it?
370 .IP \(bu 4
371 How do I look up a hash element by value?
372 .IP \(bu 4
373 How can I know how many entries are in a hash?
374 .IP \(bu 4
375 How do I sort a hash (optionally by value instead of key)?
376 .IP \(bu 4
377 How can I always keep my hash sorted?
378 .IP \(bu 4
379 What\*(Aqs the difference between "delete" and "undef" with hashes?
380 .IP \(bu 4
381 Why don\*(Aqt my tied hashes make the defined/exists distinction?
382 .IP \(bu 4
383 How do I reset an \fBeach()\fR operation part\-way through?
384 .IP \(bu 4
385 How can I get the unique keys from two hashes?
386 .IP \(bu 4
387 How can I store a multidimensional array in a DBM file?
388 .IP \(bu 4
389 How can I make my hash remember the order I put elements into it?
390 .IP \(bu 4
391 Why does passing a subroutine an undefined element in a hash create it?
392 .IP \(bu 4
393 How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
394 .IP \(bu 4
395 How can I use a reference as a hash key?
396 .IP \(bu 4
397 How can I check if a key exists in a multilevel hash?
398 .IP \(bu 4
399 How can I prevent addition of unwanted keys into a hash?
400 .IP \(bu 4
401 How do I handle binary data correctly?
402 .IP \(bu 4
403 How do I determine whether a scalar is a number/whole/integer/float?
404 .IP \(bu 4
405 How do I keep persistent data across program calls?
406 .IP \(bu 4
407 How do I print out or copy a recursive data structure?
408 .IP \(bu 4
409 How do I define methods for every class/object?
410 .IP \(bu 4
411 How do I verify a credit card checksum?
412 .IP \(bu 4
413 How do I pack arrays of doubles or floats for XS code?
414 .SS "perlfaq5: Files and Formats"
415 .IX Subsection "perlfaq5: Files and Formats"
416 This section deals with I/O and the "f" issues: filehandles, flushing, formats, and footers.
417 .IP \(bu 4
418 How do I flush/unbuffer an output filehandle? Why must I do this?
419 .IP \(bu 4
420 How do I change, delete, or insert a line in a file, or append to the beginning of a file?
421 .IP \(bu 4
422 How do I count the number of lines in a file?
423 .IP \(bu 4
424 How do I delete the last N lines from a file?
425 .IP \(bu 4
426 How can I use Perl\*(Aqs \f(CW\*(C`\-i\*(C'\fR option from within a program?
427 .IP \(bu 4
428 How can I copy a file?
429 .IP \(bu 4
430 How do I make a temporary file name?
431 .IP \(bu 4
432 How can I manipulate fixed\-record\-length files?
433 .IP \(bu 4
434 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?
435 .IP \(bu 4
436 How can I use a filehandle indirectly?
437 .IP \(bu 4
438 How can I open a filehandle to a string?
439 .IP \(bu 4
440 How can I set up a footer format to be used with \fBwrite()\fR?
441 .IP \(bu 4
442 How can I \fBwrite()\fR into a string?
443 .IP \(bu 4
444 How can I output my numbers with commas added?
445 .IP \(bu 4
446 How can I translate tildes (~) in a filename?
447 .IP \(bu 4
448 When I open a file read\-write, why does it wipe it out?
449 .IP \(bu 4
450 Why do I sometimes get an "Argument list too long" when I use <*>?
451 .IP \(bu 4
452 How can I open a file named with a leading ">" or trailing blanks?
453 .IP \(bu 4
454 How can I reliably rename a file?
455 .IP \(bu 4
456 How can I lock a file?
457 .IP \(bu 4
458 Why can\*(Aqt I just open(FH, ">file.lock")?
459 .IP \(bu 4
460 I still don\*(Aqt get locking. I just want to increment the number in the file. How can I do this?
461 .IP \(bu 4
462 All I want to do is append a small amount of text to the end of a file. Do I still have to use locking?
463 .IP \(bu 4
464 How do I randomly update a binary file?
465 .IP \(bu 4
466 How do I get a file\*(Aqs timestamp in perl?
467 .IP \(bu 4
468 How do I set a file\*(Aqs timestamp in perl?
469 .IP \(bu 4
470 How do I print to more than one file at once?
471 .IP \(bu 4
472 How can I read in an entire file all at once?
473 .IP \(bu 4
474 How can I read in a file by paragraphs?
475 .IP \(bu 4
476 How can I read a single character from a file? From the keyboard?
477 .IP \(bu 4
478 How can I tell whether there\*(Aqs a character waiting on a filehandle?
479 .IP \(bu 4
480 How do I do a \f(CW\*(C`tail \-f\*(C'\fR in perl?
481 .IP \(bu 4
482 How do I \fBdup()\fR a filehandle in Perl?
483 .IP \(bu 4
484 How do I close a file descriptor by number?
485 .IP \(bu 4
486 Why can\*(Aqt I use "C:\etemp\efoo" in DOS paths? Why doesn\*(Aqt \`C:\etemp\efoo.exe\` work?
487 .IP \(bu 4
488 Why doesn\*(Aqt glob("*.*") get all the files?
489 .IP \(bu 4
490 Why does Perl let me delete read\-only files? Why does \f(CW\*(C`\-i\*(C'\fR clobber protected files? Isn\*(Aqt this a bug in Perl?
491 .IP \(bu 4
492 How do I select a random line from a file?
493 .IP \(bu 4
494 Why do I get weird spaces when I print an array of lines?
495 .IP \(bu 4
496 How do I traverse a directory tree?
497 .IP \(bu 4
498 How do I delete a directory tree?
499 .IP \(bu 4
500 How do I copy an entire directory?
501 .SS "perlfaq6: Regular Expressions"
502 .IX Subsection "perlfaq6: Regular Expressions"
503 This section is surprisingly small because the rest of the FAQ is littered with answers involving regular expressions. For example, decoding a URL and checking whether something is a number can be handled with regular expressions, but those answers are found elsewhere in this document (in perlfaq9 : "How do I decode or create those %\-encodings on the web" and perlfaq4 : "How do I determine whether a scalar is a number/whole/integer/float", to be precise).
504 .IP \(bu 4
505 How can I hope to use regular expressions without creating illegible and unmaintainable code?
506 .IP \(bu 4
507 I\*(Aqm having trouble matching over more than one line. What\*(Aqs wrong?
508 .IP \(bu 4
509 How can I pull out lines between two patterns that are themselves on different lines?
510 .IP \(bu 4
511 How do I match XML, HTML, or other nasty, ugly things with a regex?
512 .IP \(bu 4
513 I put a regular expression into $/ but it didn\*(Aqt work. What\*(Aqs wrong?
514 .IP \(bu 4
515 How do I substitute case\-insensitively on the LHS while preserving case on the RHS?
516 .IP \(bu 4
517 How can I make \f(CW\*(C`\ew\*(C'\fR match national character sets?
518 .IP \(bu 4
519 How can I match a locale\-smart version of \f(CW\*(C`/[a\-zA\-Z]/\*(C'\fR ?
520 .IP \(bu 4
521 How can I quote a variable to use in a regex?
522 .IP \(bu 4
523 What is \f(CW\*(C`/o\*(C'\fR really for?
524 .IP \(bu 4
525 How do I use a regular expression to strip C\-style comments from a file?
526 .IP \(bu 4
527 Can I use Perl regular expressions to match balanced text?
528 .IP \(bu 4
529 What does it mean that regexes are greedy? How can I get around it?
530 .IP \(bu 4
531 How do I process each word on each line?
532 .IP \(bu 4
533 How can I print out a word\-frequency or line\-frequency summary?
534 .IP \(bu 4
535 How can I do approximate matching?
536 .IP \(bu 4
537 How do I efficiently match many regular expressions at once?
538 .IP \(bu 4
539 Why don\*(Aqt word\-boundary searches with \f(CW\*(C`\eb\*(C'\fR work for me?
540 .IP \(bu 4
541 Why does using $&, $\`, or $\*(Aq slow my program down?
542 .IP \(bu 4
543 What good is \f(CW\*(C`\eG\*(C'\fR in a regular expression?
544 .IP \(bu 4
545 Are Perl regexes DFAs or NFAs? Are they POSIX compliant?
546 .IP \(bu 4
547 What\*(Aqs wrong with using grep in a void context?
548 .IP \(bu 4
549 How can I match strings with multibyte characters?
550 .IP \(bu 4
551 How do I match a regular expression that\*(Aqs in a variable?
552 .SS "perlfaq7: General Perl Language Issues"
553 .IX Subsection "perlfaq7: General Perl Language Issues"
554 This section deals with general Perl language issues that don\*(Aqt clearly fit into any of the other sections.
555 .IP \(bu 4
556 Can I get a BNF/yacc/RE for the Perl language?
557 .IP \(bu 4
558 What are all these $@%&* punctuation signs, and how do I know when to use them?
559 .IP \(bu 4
560 Do I always/never have to quote my strings or use semicolons and commas?
561 .IP \(bu 4
562 How do I skip some return values?
563 .IP \(bu 4
564 How do I temporarily block warnings?
565 .IP \(bu 4
566 What\*(Aqs an extension?
567 .IP \(bu 4
568 Why do Perl operators have different precedence than C operators?
569 .IP \(bu 4
570 How do I declare/create a structure?
571 .IP \(bu 4
572 How do I create a module?
573 .IP \(bu 4
574 How do I adopt or take over a module already on CPAN?
575 .IP \(bu 4
576 How do I create a class?
577 .IP \(bu 4
578 How can I tell if a variable is tainted?
579 .IP \(bu 4
580 What\*(Aqs a closure?
581 .IP \(bu 4
582 What is variable suicide and how can I prevent it?
583 .IP \(bu 4
584 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
585 .IP \(bu 4
586 How do I create a static variable?
587 .IP \(bu 4
588 What\*(Aqs the difference between dynamic and lexical (static) scoping? Between \fBlocal()\fR and \fBmy()\fR?
589 .IP \(bu 4
590 How can I access a dynamic variable while a similarly named lexical is in scope?
591 .IP \(bu 4
592 What\*(Aqs the difference between deep and shallow binding?
593 .IP \(bu 4
594 Why doesn\*(Aqt "my($foo) = <$fh>;" work right?
595 .IP \(bu 4
596 How do I redefine a builtin function, operator, or method?
597 .IP \(bu 4
598 What\*(Aqs the difference between calling a function as &foo and \fBfoo()\fR?
599 .IP \(bu 4
600 How do I create a switch or case statement?
601 .IP \(bu 4
602 How can I catch accesses to undefined variables, functions, or methods?
603 .IP \(bu 4
604 Why can\*(Aqt a method included in this same file be found?
605 .IP \(bu 4
606 How can I find out my current or calling package?
607 .IP \(bu 4
608 How can I comment out a large block of Perl code?
609 .IP \(bu 4
610 How do I clear a package?
611 .IP \(bu 4
612 How can I use a variable as a variable name?
613 .IP \(bu 4
614 What does "bad interpreter" mean?
615 .IP \(bu 4
616 Do I need to recompile XS modules when there is a change in the C library?
617 .SS "perlfaq8: System Interaction"
618 .IX Subsection "perlfaq8: System Interaction"
619 This section of the Perl FAQ covers questions involving operating system interaction. Topics include interprocess communication (IPC), control over the user\-interface (keyboard, screen and pointing devices), and most anything else not related to data manipulation.
620 .IP \(bu 4
621 How do I find out which operating system I\*(Aqm running under?
622 .IP \(bu 4
623 Why does \fBexec()\fR not return?
624 .IP \(bu 4
625 How do I do fancy stuff with the keyboard/screen/mouse?
626 .IP \(bu 4
627 How do I print something out in color?
628 .IP \(bu 4
629 How do I read just one key without waiting for a return key?
630 .IP \(bu 4
631 How do I check whether input is ready on the keyboard?
632 .IP \(bu 4
633 How do I clear the screen?
634 .IP \(bu 4
635 How do I get the screen size?
636 .IP \(bu 4
637 How do I ask the user for a password?
638 .IP \(bu 4
639 How do I read and write the serial port?
640 .IP \(bu 4
641 How do I decode encrypted password files?
642 .IP \(bu 4
643 How do I start a process in the background?
644 .IP \(bu 4
645 How do I trap control characters/signals?
646 .IP \(bu 4
647 How do I modify the shadow password file on a Unix system?
648 .IP \(bu 4
649 How do I set the time and date?
650 .IP \(bu 4
651 How can I \fBsleep()\fR or \fBalarm()\fR for under a second?
652 .IP \(bu 4
653 How can I measure time under a second?
654 .IP \(bu 4
655 How can I do an \fBatexit()\fR or \fBsetjmp()\fR/\fBlongjmp()\fR? (Exception handling)
656 .IP \(bu 4
657 Why doesn\*(Aqt my sockets program work under System V (Solaris)? What does the error message "Protocol not supported" mean?
658 .IP \(bu 4
659 How can I call my system\*(Aqs unique C functions from Perl?
660 .IP \(bu 4
661 Where do I get the include files to do \fBioctl()\fR or \fBsyscall()\fR?
662 .IP \(bu 4
663 Why do setuid perl scripts complain about kernel problems?
664 .IP \(bu 4
665 How can I open a pipe both to and from a command?
666 .IP \(bu 4
667 Why can\*(Aqt I get the output of a command with \fBsystem()\fR?
668 .IP \(bu 4
669 How can I capture STDERR from an external command?
670 .IP \(bu 4
671 Why doesn\*(Aqt \fBopen()\fR return an error when a pipe open fails?
672 .IP \(bu 4
673 What\*(Aqs wrong with using backticks in a void context?
674 .IP \(bu 4
675 How can I call backticks without shell processing?
676 .IP \(bu 4
677 Why can\*(Aqt my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS\-DOS)?
678 .IP \(bu 4
679 How can I convert my shell script to perl?
680 .IP \(bu 4
681 Can I use perl to run a telnet or ftp session?
682 .IP \(bu 4
683 How can I write expect in Perl?
684 .IP \(bu 4
685 Is there a way to hide perl\*(Aqs command line from programs such as "ps"?
686 .IP \(bu 4
687 I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?
688 .IP \(bu 4
689 How do I close a process\*(Aqs filehandle without waiting for it to complete?
690 .IP \(bu 4
691 How do I fork a daemon process?
692 .IP \(bu 4
693 How do I find out if I\*(Aqm running interactively or not?
694 .IP \(bu 4
695 How do I timeout a slow event?
696 .IP \(bu 4
697 How do I set CPU limits?
698 .IP \(bu 4
699 How do I avoid zombies on a Unix system?
700 .IP \(bu 4
701 How do I use an SQL database?
702 .IP \(bu 4
703 How do I make a \fBsystem()\fR exit on control\-C?
704 .IP \(bu 4
705 How do I open a file without blocking?
706 .IP \(bu 4
707 How do I tell the difference between errors from the shell and perl?
708 .IP \(bu 4
709 How do I install a module from CPAN?
710 .IP \(bu 4
711 What\*(Aqs the difference between require and use?
712 .IP \(bu 4
713 How do I keep my own module/library directory?
714 .IP \(bu 4
715 How do I add the directory my program lives in to the module/library search path?
716 .IP \(bu 4
717 How do I add a directory to my include path (@INC) at runtime?
718 .IP \(bu 4
719 Where are modules installed?
720 .IP \(bu 4
721 What is socket.ph and where do I get it?
722 .SS "perlfaq9: Web, Email and Networking"
723 .IX Subsection "perlfaq9: Web, Email and Networking"
724 This section deals with questions related to running web sites, sending and receiving email as well as general networking.
725 .IP \(bu 4
726 Should I use a web framework?
727 .IP \(bu 4
728 Which web framework should I use?
729 .IP \(bu 4
730 What is Plack and PSGI?
731 .IP \(bu 4
732 How do I remove HTML from a string?
733 .IP \(bu 4
734 How do I extract URLs?
735 .IP \(bu 4
736 How do I fetch an HTML file?
737 .IP \(bu 4
738 How do I automate an HTML form submission?
739 .IP \(bu 4
740 How do I decode or create those %\-encodings on the web?
741 .IP \(bu 4
742 How do I redirect to another page?
743 .IP \(bu 4
744 How do I put a password on my web pages?
745 .IP \(bu 4
746 How do I make sure users can\*(Aqt enter values into a form that causes my CGI script to do bad things?
747 .IP \(bu 4
748 How do I parse a mail header?
749 .IP \(bu 4
750 How do I check a valid mail address?
751 .IP \(bu 4
752 How do I decode a MIME/BASE64 string?
753 .IP \(bu 4
754 How do I find the user\*(Aqs mail address?
755 .IP \(bu 4
756 How do I send email?
757 .IP \(bu 4
758 How do I use MIME to make an attachment to a mail message?
759 .IP \(bu 4
760 How do I read email?
761 .IP \(bu 4
762 How do I find out my hostname, domainname, or IP address?
763 .IP \(bu 4
764 How do I fetch/put an (S)FTP file?
765 .IP \(bu 4
766 How can I do RPC in Perl?
767 .SH CREDITS
768 .IX Header "CREDITS"
769 Tom Christiansen wrote the original perlfaq then expanded it with the
770 help of Nat Torkington. brian d foy substantially edited and expanded
771 the perlfaq. perlfaq\-workers and others have also supplied feedback,
772 patches and corrections over the years.
773 .SH "AUTHOR AND COPYRIGHT"
774 .IX Header "AUTHOR AND COPYRIGHT"
775 Tom Christiansen wrote the original version of this document.
776 brian d foy \f(CW\*(C`<[email protected]>\*(C'\fR wrote this version. See the
777 individual perlfaq documents for additional copyright information.
778 .PP
779 This document is available under the same terms as Perl itself. Code
780 examples in all the perlfaq documents are in the public domain. Use
781 them as you see fit (and at your own risk with no warranty from anyone).