From: brian d foy Date: Sat, 19 Dec 2009 10:27:31 +0000 (-0600) Subject: * Synced the perlfaq X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3bc3c5beacd5fac2157b8441ce88ad169a9bc6b0;p=p5sagit%2Fp5-mst-13.2.git * Synced the perlfaq The latest commit in https://github.com/briandfoy/perlfaq is 4e2e0c9bcb3404e0b09d2e61e23ba6a6095b1 dated Sat Dec 19 04:17:11 2009 -0600 --- diff --git a/pod/perlfaq2.pod b/pod/perlfaq2.pod index f578d41..d558172 100644 --- a/pod/perlfaq2.pod +++ b/pod/perlfaq2.pod @@ -54,7 +54,7 @@ IndigoPerl: Windows Since you don't have a C compiler, you're doomed and your vendor should be sacrificed to the Sun gods. But that doesn't help you. -What you need to do is get a binary version of gcc for your system +What you need to do is get a binary version of C for your system first. Consult the Usenet FAQs for your operating system for information on where to get such a binary version. @@ -77,13 +77,13 @@ eventually live on, and then type C. Most other approaches are doomed to failure. One simple way to check that things are in the right place is to print out -the hard-coded @INC that perl looks through for libraries: +the hard-coded C<@INC> that perl looks through for libraries: % perl -le 'print for @INC' If this command lists any paths that don't exist on your system, then you may need to move the appropriate libraries to these locations, or create -symbolic links, aliases, or shortcuts appropriately. @INC is also printed as +symbolic links, aliases, or shortcuts appropriately. C<@INC> is also printed as part of the output of % perl -V @@ -95,7 +95,7 @@ L. Read the F file, which is part of the source distribution. It describes in detail how to cope with most idiosyncrasies that the -Configure script can't work around for any given system or +C script can't work around for any given system or architecture. =head2 What modules and extensions are available for Perl? What is CPAN? What does CPAN/src/... mean? @@ -116,16 +116,16 @@ See the CPAN FAQ at http://www.cpan.org/misc/cpan-faq.html for answers to the most frequently asked questions about CPAN including how to become a mirror. -CPAN/path/... is a naming convention for files available on CPAN +C is a naming convention for files available on CPAN sites. CPAN indicates the base directory of a CPAN mirror, and the rest of the path is the path from that directory to the file. For instance, if you're using ftp://ftp.funet.fi/pub/languages/perl/CPAN -as your CPAN site, the file CPAN/misc/japh is downloadable as +as your CPAN site, the file C is downloadable as ftp://ftp.funet.fi/pub/languages/perl/CPAN/misc/japh . Considering that, as of 2006, there are over ten thousand existing modules in the archive, one probably exists to do nearly anything you -can think of. Current categories under CPAN/modules/by-category/ +can think of. Current categories under C include Perl core modules; development support; operating system interfaces; networking, devices, and interprocess communication; data type utilities; database interfaces; user interfaces; interfaces to @@ -151,13 +151,13 @@ The complete Perl documentation is available with the Perl distribution. If you have Perl installed locally, you probably have the documentation installed as well: type C if you're on a system resembling Unix. This will lead you to other important man pages, including how to set your -$MANPATH. If you're not on a Unix system, access to the documentation +C<$MANPATH>. If you're not on a Unix system, access to the documentation will be different; for example, documentation might only be in HTML format. All proper perl installations have fully-accessible documentation. You might also try C in case your system doesn't -have a proper man command, or it's been misinstalled. If that doesn't -work, try looking in /usr/local/lib/perl5/pod for documentation. +have a proper C command, or it's been misinstalled. If that doesn't +work, try looking in C for documentation. If all else fails, consult http://perldoc.perl.org/ which has the complete documentation in HTML and PDF format. @@ -323,7 +323,7 @@ Recommended books on (or mostly on) Perl follow. Writing Perl Modules for CPAN by Sam Tregar - ISBN 1-59059-018-X [1st edition Aug 2002] + ISBN 1-59059-018-X [1st edition August 2002] http://apress.com/book/bookDisplay.html?bID=14 The Perl Cookbook @@ -370,13 +370,13 @@ Recommended books on (or mostly on) Perl follow. http://www.awlonline.com/ Object Oriented Perl - Damian Conway + by Damian Conway with foreword by Randal L. Schwartz ISBN 1-884777-79-1 [1st edition August 1999] http://www.manning.com/conway/ Data Munging with Perl - Dave Cross + by Dave Cross ISBN 1-930110-00-6 [1st edition 2001] http://www.manning.com/cross @@ -409,11 +409,14 @@ almost completely (although it sometimes sneaks in an article about another language). There's also I<$foo Magazin>, a german magazine dedicated to Perl, at ( http://www.foo-magazin.de ). +The I is a German-speaking magazine for Perl beginners +(see http://perl-zeitung.at.tf ). + Magazines that frequently carry quality articles on Perl include I ( http://www.theperlreview.com ), I ( http://www.unixreview.com/ ), I ( http://www.linuxmagazine.com/ ), and Usenix's newsletter/magazine to -its members, I ( http://www.usenix.org/ ) +its members, I ( http://www.usenix.org/ ). The Perl columns of Randal L. Schwartz are available on the web at http://www.stonehenge.com/merlyn/WebTechniques/ , @@ -425,15 +428,15 @@ Perl, I contains tutorials, demonstrations, case studies, announcements, contests, and much more. I has columns on web development, databases, Win32 Perl, graphical programming, regular expressions, and networking, and sponsors the Obfuscated Perl -Contest and the Perl Poetry Contests. Beginning in November 2002, TPJ +Contest and the Perl Poetry Contests. Beginning in November 2002, I moved to a reader-supported monthly e-zine format in which subscribers -can download issues as PDF documents. In 2006, TPJ merged with Dr. -Dobbs Journal (online edition). To read old TPJ articles, see +can download issues as PDF documents. In 2006, I merged with Dr. +Dobbs Journal (online edition). To read old I articles, see http://www.ddj.com/ . =head2 What mailing lists are there for Perl? -Most of the major modules (Tk, CGI, libwww-perl) have their own +Most of the major modules (C, C, C) have their own mailing lists. Consult the documentation that came with the module for subscription information. @@ -491,6 +494,9 @@ To determine if a module came with your version of Perl, you can use the C module. It has the information about the modules (with their versions) included with each release of Perl. +If C is not installed on your system, check out +http://perlpunks.de/corelist . + Every CPAN module has a bug tracker set up in RT, http://rt.cpan.org . You can submit bugs to RT either through its web interface or by email. To email a bug report, send it to diff --git a/pod/perlfaq3.pod b/pod/perlfaq3.pod index c1ba5bb..6b2a046 100644 --- a/pod/perlfaq3.pod +++ b/pod/perlfaq3.pod @@ -31,7 +31,7 @@ A crude table of contents for the Perl manpage set is found in L. =head2 How can I use Perl interactively? The typical approach uses the Perl debugger, described in the -perldebug(1) manpage, on an "empty" program, like this: +C manpage, on an "empty" program, like this: perl -de 42 @@ -42,21 +42,21 @@ operations typically found in symbolic debuggers. =head2 Is there a Perl shell? -The psh (Perl sh) is currently at version 1.8. The Perl Shell is a shell +The C (Perl sh) is currently at version 1.8. The Perl Shell is a shell that combines the interactive nature of a Unix shell with the power of Perl. The goal is a full featured shell that behaves as expected for normal shell activity and uses Perl syntax and functionality for -control-flow statements and other things. You can get psh at +control-flow statements and other things. You can get C at http://sourceforge.net/projects/psh/ . -Zoidberg is a similar project and provides a shell written in perl, +C is a similar project and provides a shell written in perl, configured in perl and operated in perl. It is intended as a login shell and development environment. It can be found at http://pardus-larus.student.utwente.nl/~pardus/projects/zoidberg/ or your local CPAN mirror. -The Shell.pm module (distributed with Perl) makes Perl try commands -which aren't part of the Perl language as shell commands. perlsh from +The C module (distributed with Perl) makes Perl try commands +which aren't part of the Perl language as shell commands. C from the source distribution is simplistic and uninteresting, but may still be what you want. @@ -71,7 +71,7 @@ that C understands and can use to re-install every module: $ cpan -a -Inside a Perl program, you can use the ExtUtils::Installed module to +Inside a Perl program, you can use the C module to show all installed distributions, although it can take awhile to do its magic. The standard library which comes with Perl just shows up as "Perl" (although you can get those with C). @@ -94,7 +94,7 @@ can use C: ; If you do not have that module, you can do the same thing -with File::Find which is part of the standard library: +with C which is part of the standard library: use File::Find; my @files; @@ -153,11 +153,11 @@ The C module can pretty-print Perl data structures: Perl comes with an interactive debugger, which you can start with the C<-d> switch. It's fully explained in L. -If you'd like a graphical user interface and you have Tk, you can use +If you'd like a graphical user interface and you have C, you can use C. It's on CPAN and available for free. If you need something much more sophisticated and controllable, Leon -Brocard's Devel::ebug (which you can call with the -D switch as -Debug) +Brocard's C (which you can call with the C<-D> switch as C<-Debug>) gives you the programmatic hooks into everything you need to write your own (without too much pain and suffering). @@ -182,7 +182,7 @@ C. dprofpp You can also do the profiling and reporting in one step with the C<-p> -switch to : +switch to C: dprofpp -p program.pl @@ -224,18 +224,18 @@ http://www.stonehenge.com/merlyn/LinuxMag/col75.html . =head2 How do I cross-reference my Perl programs? -The B::Xref module can be used to generate cross-reference reports +The C module can be used to generate cross-reference reports for Perl programs. perl -MO=Xref[,OPTIONS] scriptname.plx =head2 Is there a pretty-printer (formatter) for Perl? -Perltidy is a Perl script which indents and reformats Perl scripts +C is a Perl script which indents and reformats Perl scripts to make them easier to read by trying to follow the rules of the L. If you write Perl scripts, or spend much time reading them, you will probably find it useful. It is available at -http://perltidy.sourceforge.net +http://perltidy.sourceforge.net . Of course, if you simply follow the guidelines in L, you shouldn't need to reformat. The habit of formatting your code diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index df813da..8d5e2e6 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -21,7 +21,7 @@ L shows the gory details of number representations and conversions. To limit the number of decimal places in your numbers, you can use the -printf or sprintf function. See the L<"Floating Point +C or C function. See the L<"Floating Point Arithmetic"|perlop> for more details. printf "%.2f", 10/3; @@ -533,35 +533,30 @@ you'll still end up on the previous calendar day, although not at noon. Since you don't care about the time, the one hour difference doesn't matter and you end up with the previous date. -=head2 Does Perl have a Year 2000 problem? Is Perl Y2K compliant? - -Short answer: No, Perl does not have a Year 2000 problem. Yes, Perl is -Y2K compliant (whatever that means). The programmers you've hired to -use it, however, probably are not. - -Long answer: The question belies a true understanding of the issue. -Perl is just as Y2K compliant as your pencil--no more, and no less. -Can you use your pencil to write a non-Y2K-compliant memo? Of course -you can. Is that the pencil's fault? Of course it isn't. - -The date and time functions supplied with Perl (gmtime and localtime) -supply adequate information to determine the year well beyond 2000 -(2038 is when trouble strikes for 32-bit machines). The year returned -by these functions when used in a list context is the year minus 1900. -For years between 1910 and 1999 this I to be a 2-digit decimal -number. To avoid the year 2000 problem simply do not treat the year as -a 2-digit number. It isn't. - -When gmtime() and localtime() are used in scalar context they return -a timestamp string that contains a fully-expanded year. For example, -C<$timestamp = gmtime(1005613200)> sets $timestamp to "Tue Nov 13 01:00:00 -2001". There's no year 2000 problem here. - -That doesn't mean that Perl can't be used to create non-Y2K compliant -programs. It can. But so can your pencil. It's the fault of the user, -not the language. At the risk of inflaming the NRA: "Perl doesn't -break Y2K, people do." See http://www.perl.org/about/y2k.html for -a longer exposition. +=head2 Does Perl have a Year 2000 or 2038 problem? Is Perl Y2K compliant? + +(contributed by brian d foy) + +Perl itself never had a Y2K problem, although that nevers stopped people +from creating Y2K problems on their own. See the documentation for +C for its proper use. + +Starting with Perl 5.11, C and C can handle dates past +03:14:08 January 19, 2038, when a 32-bit based time would overflow. You +still might get a warning on a 32-bit C: + + % perl5.11.2 -E 'say scalar localtime( 0x9FFF_FFFFFFFF )' + Integer overflow in hexadecimal number at -e line 1. + Wed Nov 1 19:42:39 5576711 + +On a 64-bit C, you can get even larger dates for those really long +running projects: + + % perl5.11.2 -E 'say scalar gmtime( 0x9FFF_FFFFFFFF )' + Thu Nov 2 00:42:39 5576711 + +You're still out of luck if you need to keep tracking of decaying protons +though. =head1 Data: Strings diff --git a/pod/perlfaq8.pod b/pod/perlfaq8.pod index 8682b4d..adda585 100644 --- a/pod/perlfaq8.pod +++ b/pod/perlfaq8.pod @@ -15,7 +15,7 @@ contain more detailed information on the vagaries of your perl. =head2 How do I find out which operating system I'm running under? -The $^O variable ($OSNAME if you use English) contains an indication of +The C<$^O> variable (C<$OSNAME> if you use C) contains an indication of the name of the operating system (not its release number) that your perl binary was built for. @@ -66,7 +66,7 @@ in this section of the perlfaq. In general, you don't, because you don't know whether the recipient has a color-aware display device. If you know that they have an ANSI terminal that understands -color, you can use the Term::ANSIColor module from CPAN: +color, you can use the C module from CPAN: use Term::ANSIColor; print color("red"), "Stop!\n", color("reset"); @@ -92,7 +92,7 @@ portability snags. sysread(TTY, $key, 1); # probably this does system "stty -cbreak /dev/tty 2>&1"; -The Term::ReadKey module from CPAN offers an easy-to-use interface that +The C module from CPAN offers an easy-to-use interface that should be more efficient than shelling out to B for each key. It even includes limited support for Windows. @@ -103,13 +103,13 @@ It even includes limited support for Windows. However, using the code requires that you have a working C compiler and can use it to build and install a CPAN module. Here's a solution -using the standard POSIX module, which is already on your systems +using the standard C module, which is already on your systems (assuming your system supports POSIX). use HotKey; $key = readkey(); -And here's the HotKey module, which hides the somewhat mystifying calls +And here's the C module, which hides the somewhat mystifying calls to manipulate the POSIX termios structures. # HotKey.pm @@ -157,7 +157,7 @@ to manipulate the POSIX termios structures. =head2 How do I check whether input is ready on the keyboard? The easiest way to do this is to read a key in nonblocking mode with the -Term::ReadKey module from CPAN, passing it an argument of -1 to indicate +C module from CPAN, passing it an argument of -1 to indicate not to block: use Term::ReadKey; @@ -220,7 +220,7 @@ later: =head2 How do I get the screen size? -If you have Term::ReadKey module installed from CPAN, +If you have C module installed from CPAN, you can use it to fetch the width and height in characters and in pixels: @@ -248,11 +248,11 @@ FAQ for that.) There's an example of this in L). First, you put the terminal into "no echo" mode, then just read the password normally. -You may do this with an old-style ioctl() function, POSIX terminal +You may do this with an old-style C function, POSIX terminal control (see L or its documentation the Camel Book), or a call to the B program, with varying degrees of portability. -You can also do this for most systems using the Term::ReadKey module +You can also do this for most systems using the C module from CPAN, which is easier to use and in theory more portable. use Term::ReadKey; @@ -281,8 +281,8 @@ from multiple processes reading from one device. If you expect to use both read and write operations on the device, you'll have to open it for update (see L for details). You may wish to open it without running the risk of -blocking by using sysopen() and C from the -Fcntl module (part of the standard perl distribution). See +blocking by using C and C from the +C module (part of the standard perl distribution). See L for more on this approach. =item end of line @@ -305,8 +305,8 @@ next. =item flushing output -If you expect characters to get to your device when you print() them, -you'll want to autoflush that filehandle. You can use select() +If you expect characters to get to your device when you C them, +you'll want to autoflush that filehandle. You can use C and the C<$|> variable to control autoflushing (see L> and L, or L, "How do I flush/unbuffer an output filehandle? Why must I do this?"): @@ -320,7 +320,7 @@ You'll also see code that does this without a temporary variable, as in select((select(DEV), $| = 1)[0]); Or if you don't mind pulling in a few thousand lines -of code just because you're afraid of a little $| variable: +of code just because you're afraid of a little C<$|> variable: use IO::Handle; DEV->autoflush(1); @@ -331,18 +331,18 @@ line terminators, in that case. =item non-blocking input -If you are doing a blocking read() or sysread(), you'll have to +If you are doing a blocking C or C, you'll have to arrange for an alarm handler to provide a timeout (see L). If you have a non-blocking open, you'll likely have a non-blocking read, which means you may have to use a 4-arg -select() to determine whether I/O is ready on that device (see +C to determine whether I/O is ready on that device (see L. =back While trying to read from his caller-id box, the notorious Jamie Zawinski -C<< >>, after much gnashing of teeth and fighting with sysread, -sysopen, POSIX's tcgetattr business, and various other functions that +C<< >>, after much gnashing of teeth and fighting with C, +C, POSIX's C business, and various other functions that go bump in the night, finally came up with this: sub open_modem { @@ -384,9 +384,9 @@ have to wait for it to finish before your program moves on to other tasks. Process management depends on your particular operating system, and many of the techniques are in L. -Several CPAN modules may be able to help, including IPC::Open2 or -IPC::Open3, IPC::Run, Parallel::Jobs, Parallel::ForkManager, POE, -Proc::Background, and Win32::Process. There are many other modules you +Several CPAN modules may be able to help, including C or +C, C, C, C, C, +C, and C. There are many other modules you might use, so check those namespaces for other options too. If you are on a unix-like system, you might be able to get away with a @@ -424,8 +424,8 @@ You have to be prepared to "reap" the child process when it finishes. $SIG{CHLD} = 'IGNORE'; -You can also use a double fork. You immediately wait() for your -first child, and the init daemon will wait() for your grandchild once +You can also use a double fork. You immediately C for your +first child, and the init daemon will C for your grandchild once it exits. unless ($pid = fork) { @@ -450,8 +450,8 @@ foregrounded process group, which you then trap in your process. Signals are documented in L and the section on "Signals" in the Camel. -You can set the values of the %SIG hash to be the functions you want -to handle the signal. After perl catches the signal, it looks in %SIG +You can set the values of the C<%SIG> hash to be the functions you want +to handle the signal. After perl catches the signal, it looks in C<%SIG> for a key with the same name as the signal, then calls the subroutine value for that key. @@ -469,24 +469,24 @@ value for that key. Perl versions before 5.8 had in its C source code signal handlers which would catch the signal and possibly run a Perl function that you had set -in %SIG. This violated the rules of signal handling at that level -causing perl to dump core. Since version 5.8.0, perl looks at %SIG -*after* the signal has been caught, rather than while it is being caught. +in C<%SIG>. This violated the rules of signal handling at that level +causing perl to dump core. Since version 5.8.0, perl looks at C<%SIG> +B the signal has been caught, rather than while it is being caught. Previous versions of this answer were incorrect. =head2 How do I modify the shadow password file on a Unix system? If perl was installed correctly and your shadow library was written -properly, the getpw*() functions described in L should in +properly, the C functions described in L should in theory provide (read-only) access to entries in the shadow password file. To change the file, make a new shadow password file (the format varies from system to system--see L for specifics) and use -pwd_mkdb(8) to install it (see L for more details). +C to install it (see L for more details). =head2 How do I set the time and date? Assuming you're running under sufficient permissions, you should be -able to set the system-wide date and time by running the date(1) +able to set the system-wide date and time by running the C program. (There is no way to set the time and date on a per-process basis.) This mechanism will work for Unix, MS-DOS, Windows, and NT; the VMS equivalent is C. @@ -522,7 +522,7 @@ L. =head2 How can I do an atexit() or setjmp()/longjmp()? (Exception handling) Release 5 of Perl added the END block, which can be used to simulate -atexit(). Each package's END block is called when the program or +C. Each package's END block is called when the program or thread ends (see L manpage for more details). For example, you can use this to make sure your filter program @@ -532,19 +532,19 @@ managed to finish its output without filling up the disk: close(STDOUT) || die "stdout close failed: $!"; } -The END block isn't called when untrapped signals kill the program, -though, so if you use END blocks you should also use +The C block isn't called when untrapped signals kill the program, +though, so if you use C blocks you should also use use sigtrap qw(die normal-signals); -Perl's exception-handling mechanism is its eval() operator. You can -use eval() as setjmp and die() as longjmp. For details of this, see +Perl's exception-handling mechanism is its C operator. You can +use C as C and C as C. For details of this, see the section on signals, especially the time-out handler for a blocking -flock() in L or the section on "Signals" in +C in L or the section on "Signals" in the Camel Book. If exception handling is all you're interested in, try the -exceptions.pl library (part of the standard perl distribution). +C library (part of the standard perl distribution). If you want the atexit() syntax (and an rmexit() as well), try the AtExit module available from CPAN. @@ -564,24 +564,24 @@ values are different. Go figure. In most cases, you write an external module to do it--see the answer to "Where can I learn about linking C with Perl? [h2xs, xsubpp]". However, if the function is a system call, and your system supports -syscall(), you can use the syscall function (documented in +C, you can use the C function (documented in L). Remember to check the modules that came with your distribution, and CPAN as well--someone may already have written a module to do it. On -Windows, try Win32::API. On Macs, try Mac::Carbon. If no module +Windows, try C. On Macs, try C. If no module has an interface to the C function, you can inline a bit of C in your -Perl source with Inline::C. +Perl source with C. =head2 Where do I get the include files to do ioctl() or syscall()? -Historically, these would be generated by the h2ph tool, part of the -standard perl distribution. This program converts cpp(1) directives +Historically, these would be generated by the C tool, part of the +standard perl distribution. This program converts C directives in C header files to files containing subroutine definitions, like -&SYS_getitimer, which you can use as arguments to your functions. +C<&SYS_getitimer>, which you can use as arguments to your functions. It doesn't work perfectly, but it usually gets most of the job done. Simple files like F, F, and F were fine, -but the hard ones like F nearly always need to hand-edited. +but the hard ones like F nearly always need to be hand-edited. Here's how to install the *.ph files: 1. become super-user @@ -589,12 +589,12 @@ Here's how to install the *.ph files: 3. h2ph *.h */*.h If your system supports dynamic loading, for reasons of portability and -sanity you probably ought to use h2xs (also part of the standard perl +sanity you probably ought to use C (also part of the standard perl distribution). This tool converts C header files to Perl extensions. -See L for how to get started with h2xs. +See L for how to get started with C. If your system doesn't support dynamic loading, you still probably -ought to use h2xs. See L and L for +ought to use C. See L and L for more information (in brief, just use B instead of a plain B to rebuild perl with a new static extension). @@ -606,20 +606,20 @@ scripts inherently insecure. Perl gives you a number of options =head2 How can I open a pipe both to and from a command? -The IPC::Open2 module (part of the standard perl distribution) is an -easy-to-use approach that internally uses pipe(), fork(), and exec() to do -the job. Make sure you read the deadlock warnings in its documentation, +The C module (part of the standard perl distribution) is an +easy-to-use approach that internally uses C, C, and C +to do the job. Make sure you read the deadlock warnings in its documentation, though (see L). See L and L -You may also use the IPC::Open3 module (part of the standard perl +You may also use the C module (part of the standard perl distribution), but be warned that it has a different order of -arguments from IPC::Open2 (see L). +arguments from C (see L). =head2 Why can't I get the output of a command with system()? -You're confusing the purpose of system() and backticks (``). system() +You're confusing the purpose of C and backticks (``). C runs a command and returns exit status information (as a 16 bit value: the low 7 bits are the signal the process died from, if any, and the high 8 bits are the actual exit value). Backticks (``) run a @@ -636,11 +636,11 @@ There are three basic ways of running external commands: $output = `$cmd`; # using backticks (``) open (PIPE, "cmd |"); # using open() -With system(), both STDOUT and STDERR will go the same place as the -script's STDOUT and STDERR, unless the system() command redirects them. -Backticks and open() read B the STDOUT of your command. +With C, both STDOUT and STDERR will go the same place as the +script's STDOUT and STDERR, unless the C command redirects them. +Backticks and C read B the STDOUT of your command. -You can also use the open3() function from IPC::Open3. Benjamin +You can also use the C function from C. Benjamin Goldberg provides some sample code: To capture a program's STDOUT, but discard its STDERR: @@ -686,7 +686,7 @@ files: while( ) {} while( ) {} -But there's no real need for *both* to be tempfiles... the following +But there's no real need for B to be tempfiles... the following should work just as well, without deadlocking: use IPC::Open3; @@ -725,13 +725,13 @@ This doesn't work: open(STDERR, ">&STDOUT"); $alloutput = `cmd args`; # stderr still escapes -This fails because the open() makes STDERR go to where STDOUT was -going at the time of the open(). The backticks then make STDOUT go to +This fails because the C makes STDERR go to where STDOUT was +going at the time of the C. The backticks then make STDOUT go to a string, but don't change STDERR (which still goes to the old STDOUT). -Note that you I use Bourne shell (sh(1)) redirection syntax in -backticks, not csh(1)! Details on why Perl's system() and backtick +Note that you I use Bourne shell (C) redirection syntax in +backticks, not C! Details on why Perl's C and backtick and pipe opens all use the Bourne shell are in the F article in the "Far More Than You Ever Wanted To Know" collection in http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz . To @@ -778,17 +778,17 @@ there, and the old standard error shows up on the old standard out. =head2 Why doesn't open() return an error when a pipe open fails? -If the second argument to a piped open() contains shell -metacharacters, perl fork()s, then exec()s a shell to decode the +If the second argument to a piped C contains shell +metacharacters, perl Cs, then Cs a shell to decode the metacharacters and eventually run the desired program. If the program couldn't be run, it's the shell that gets the message, not Perl. All your Perl program can find out is whether the shell itself could be successfully started. You can still capture the shell's STDERR and check it for error messages. See L<"How can I capture STDERR from an external command?"> elsewhere in this document, or use the -IPC::Open3 module. +C module. -If there are no shell metacharacters in the argument of open(), Perl +If there are no shell metacharacters in the argument of C, Perl runs the command directly, without using the shell, and can correctly report whether the command started. @@ -865,8 +865,8 @@ stuck, because Windows does not have an argc/argv-style API. This happens only if your perl is compiled to use stdio instead of perlio, which is the default. Some (maybe all?) stdio's set error and -eof flags that you may need to clear. The POSIX module defines -clearerr() that you can use. That is the technically correct way to +eof flags that you may need to clear. The C module defines +C that you can use. That is the technically correct way to do it. Here are some less reliable workarounds: =over 4 @@ -906,10 +906,10 @@ causes many inefficiencies. =head2 Can I use perl to run a telnet or ftp session? -Try the Net::FTP, TCP::Client, and Net::Telnet modules (available from +Try the C, C, and C modules (available from CPAN). http://www.cpan.org/scripts/netstuff/telnet.emul.shar -will also help for emulating the telnet protocol, but Net::Telnet is -quite probably easier to use.. +will also help for emulating the telnet protocol, but C is +quite probably easier to use. If all you want to do is pretend to be telnet but don't need the initial telnet handshaking, then the standard dual-process @@ -930,11 +930,11 @@ approach will suffice: =head2 How can I write expect in Perl? -Once upon a time, there was a library called chat2.pl (part of the +Once upon a time, there was a library called L (part of the standard perl distribution), which never really got finished. If you find it somewhere, I. These days, your best bet is to look at the Expect module available from CPAN, which also requires two -other modules from CPAN, IO::Pty and IO::Stty. +other modules from CPAN, C and C. =head2 Is there a way to hide perl's command line from programs such as "ps"? @@ -961,7 +961,7 @@ In the strictest sense, it can't be done--the script executes as a different process from the shell it was started from. Changes to a process are not reflected in its parent--only in any children created after the change. There is shell magic that may allow you to -fake it by eval()ing the script's output in your shell; check out the +fake it by Cing the script's output in your shell; check out the comp.unix.questions FAQ for details. =back @@ -984,7 +984,7 @@ module for other solutions. =item * Open /dev/tty and use the TIOCNOTTY ioctl on it. See L -for details. Or better yet, you can just use the POSIX::setsid() +for details. Or better yet, you can just use the C function, so you don't have to worry about process groups. =item * @@ -1004,7 +1004,7 @@ Background yourself like this: =back -The Proc::Daemon module, available from CPAN, provides a function to +The C module, available from CPAN, provides a function to perform these actions for you. =head2 How do I find out if I'm running interactively or not? @@ -1048,12 +1048,12 @@ Testers, for instance, set the value of C: =head2 How do I timeout a slow event? -Use the alarm() function, probably in conjunction with a signal +Use the C function, probably in conjunction with a signal handler, as documented in L and the section on "Signals" in the Camel. You may instead use the more flexible -Sys::AlarmCall module available from CPAN. +C module available from CPAN. -The alarm() function is not implemented on all versions of Windows. +The C function is not implemented on all versions of Windows. Check the documentation for your specific version of Perl. =head2 How do I set CPU limits? @@ -1078,25 +1078,25 @@ details. =head2 How do I avoid zombies on a Unix system? -Use the reaper code from L to call wait() when a +Use the reaper code from L to call C when a SIGCHLD is received, or else use the double-fork technique described in L. =head2 How do I use an SQL database? -The DBI module provides an abstract interface to most database +The C module provides an abstract interface to most database servers and types, including Oracle, DB2, Sybase, mysql, Postgresql, ODBC, and flat files. The DBI module accesses each database type through a database driver, or DBD. You can see a complete list of available drivers on CPAN: http://www.cpan.org/modules/by-module/DBD/ . You can read more about DBI on http://dbi.perl.org . -Other modules provide more specific access: Win32::ODBC, Alzabo, iodbc, +Other modules provide more specific access: C, C, C, and others found on CPAN Search: http://search.cpan.org . =head2 How do I make a system() exit on control-C? -You can't. You need to imitate the system() call (see L for +You can't. You need to imitate the C call (see L for sample code) and then have a signal handler for the INT signal that passes the signal on to the subprocess. Or you can check for it: @@ -1107,8 +1107,8 @@ passes the signal on to the subprocess. Or you can check for it: If you're lucky enough to be using a system that supports non-blocking reads (most Unixish systems do), you need only to use the -O_NDELAY or O_NONBLOCK flag from the Fcntl module in conjunction with -sysopen(): +C or C flag from the C module in conjunction with +C: use Fcntl; sysopen(FH, "/foo/somefile", O_WRONLY|O_NDELAY|O_CREAT, 0644) @@ -1133,7 +1133,7 @@ Consider this script, which has an error you may not notice immediately. print "Hello World\n"; I get an error when I run this from my shell (which happens to be -bash). That may look like perl forgot it has a print() function, +bash). That may look like perl forgot it has a C function, but my shebang line is not the path to perl, so the shell runs the script, and I get the error. @@ -1154,7 +1154,7 @@ you need to figure out the problem. $x / 0; __END__ -The perl message comes out with "Perl" in front. The BEGIN block +The perl message comes out with "Perl" in front. The C block works at compile time so all of the compilation errors and warnings get the "Perl:" prefix too. @@ -1170,7 +1170,7 @@ If I don't see that "Perl:", it's not from perl. You could also just know all the perl errors, and although there are some people who may know all of them, you probably don't. However, they -all should be in the perldiag manpage. If you don't find the error in +all should be in the L manpage. If you don't find the error in there, it probably isn't a perl error. Looking up every message is not the easiest way, so let perl to do it @@ -1265,7 +1265,7 @@ when generating Makefiles: perl Makefile.PL INSTALL_BASE=/mydir/perl -You can set this in your CPAN.pm configuration so modules automatically install +You can set this in your C configuration so modules automatically install in your private library directory when you use the CPAN.pm shell: % cpan @@ -1276,7 +1276,7 @@ For C-based distributions, use the --install_base option: perl Build.PL --install_base /mydir/perl -You can configure CPAN.pm to automatically use this option too: +You can configure C to automatically use this option too: % cpan cpan> o conf mbuild_arg --install_base /mydir/perl @@ -1289,11 +1289,11 @@ installed modules. There is one caveat with INSTALL_BASE, though, since it acts differently than the PREFIX and LIB settings that older versions of -ExtUtils::MakeMaker advocated. INSTALL_BASE does not support +C advocated. INSTALL_BASE does not support installing modules for multiple versions of Perl or different architectures under the same directory. You should consider if you really want that , and if you do, use the older PREFIX and LIB -settings. See the ExtUtils::Makemaker documentation for more details. +settings. See the C documentation for more details. =head2 How do I add the directory my program lives in to the module/library search path? @@ -1364,13 +1364,13 @@ environment variables, run-time switches, and in-code statements: =back The last is particularly useful because it knows about machine -dependent architectures. The lib.pm pragmatic module was first +dependent architectures. The C pragmatic module was first included with the 5.002 release of Perl. =head2 What is socket.ph and where do I get it? It's a Perl 4 style file defining values for system networking -constants. Sometimes it is built using h2ph when Perl is installed, +constants. Sometimes it is built using C when Perl is installed, but other times it is not. Modern programs C instead. =head1 REVISION diff --git a/pod/perlfaq9.pod b/pod/perlfaq9.pod index 190cd68..4839b0a 100644 --- a/pod/perlfaq9.pod +++ b/pod/perlfaq9.pod @@ -278,9 +278,9 @@ returns the escaped string: my $original = "Colon : Hash # Percent %"; - my $escaped = uri_escape( $original ) + my $escaped = uri_escape( $original ); - print "$escaped\n"; # 'Colon%20%3A%20Hash%20%23%20Percent%20%25%20' + print "$escaped\n"; # 'Colon%20%3A%20Hash%20%23%20Percent%20%25' To decode the string, use the C function: @@ -406,7 +406,7 @@ for you, too. Many people try to write their own decoder (or copy one from another program) and then run into one of the many "gotchas" -of the task. It's much easier and less hassle to use CGI.pm. +of the task. It's much easier and less hassle to use C. =head2 How do I check a valid mail address? @@ -470,7 +470,7 @@ the MIME/QP encoding. Decoding BASE64 becomes as simple as: use MIME::Base64; $decoded = decode_base64($encoded); -The MIME-Tools package (available from CPAN) supports extraction with +The C package (available from CPAN) supports extraction with decoding of BASE64 encoded attachments and content directly from email messages. @@ -497,7 +497,7 @@ that the company's mail system will not accept, so you should ask for users' mail addresses when this matters. Furthermore, not all systems on which Perl runs are so forthcoming with this information as is Unix. -The C module from CPAN (part of the MailTools package) provides a +The C module from CPAN (part of the C package) provides a C function that tries to guess the mail address of the user. It makes a more intelligent guess than the code above, using information given when the module was installed, but it could still be incorrect. @@ -519,19 +519,19 @@ Use the C program directly: EOF close(SENDMAIL) or warn "sendmail didn't close nicely"; -The B<-oi> option prevents sendmail from interpreting a line consisting +The B<-oi> option prevents C from interpreting a line consisting of a single dot as "end of message". The B<-t> option says to use the headers to decide who to send the message to, and B<-odq> says to put the message into the queue. This last option means your message won't be immediately delivered, so leave it out if you want immediate delivery. -Alternate, less convenient approaches include calling mail (sometimes -called mailx) directly or simply opening up port 25 have having an +Alternate, less convenient approaches include calling C (sometimes +called C) directly or simply opening up port 25 have having an intimate conversation between just you and the remote SMTP daemon, -probably sendmail. +probably C. -Or you might be able use the CPAN module Mail::Mailer: +Or you might be able use the CPAN module C: use Mail::Mailer; @@ -546,7 +546,7 @@ Or you might be able use the CPAN module Mail::Mailer: The C module uses C which is less Unix-centric than C, but less reliable. Avoid raw SMTP commands. There -are many reasons to use a mail transport agent like sendmail. These +are many reasons to use a mail transport agent like C. These include queuing, MX records, and security. =head2 How do I use MIME to make an attachment to a mail message? @@ -639,7 +639,7 @@ perl5.6, can also get the hostname. To get the IP address, you can use the C built-in function to turn the name into a number. To turn that number into the dotted octet form (a.b.c.d) that most people expect, use the C function -from the module, which also comes with perl. +from the C module, which also comes with perl. use Socket;