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