X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfaq8.pod;h=2fceab143f5a481a2945c63a61593cf533879f54;hb=5355f3c7126474078b6e199097ac1d1343f2fdb1;hp=e00d007912dfbc40ad7a3cbb5accc189c95ba7fe;hpb=49d635f9372392ae44fe4c5b62b06e41912ae0c9;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfaq8.pod b/pod/perlfaq8.pod index e00d007..2fceab1 100644 --- a/pod/perlfaq8.pod +++ b/pod/perlfaq8.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq8 - System Interaction ($Revision: 1.14 $, $Date: 2002/11/10 17:35:47 $) +perlfaq8 - System Interaction ($Revision: 1.17 $, $Date: 2003/01/26 17:44:04 $) =head1 DESCRIPTION @@ -77,7 +77,7 @@ Or like this: Controlling input buffering is a remarkably system-dependent matter. On many systems, you can just use the B command as shown in L, but as you see, that's already getting you into -portability snags. +portability snags. open(TTY, "+/dev/tty 2>&1"; @@ -188,14 +188,14 @@ positions, etc, you might wish to use Term::Cap module: =head2 How do I get the screen size? -If you have Term::ReadKey module installed from CPAN, +If you have Term::ReadKey module installed from CPAN, you can use it to fetch the width and height in characters and in pixels: use Term::ReadKey; ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize(); -This is more portable than the raw C, but not as +This is more portable than the raw C, but not as illustrative: require 'sys/ioctl.ph'; @@ -275,7 +275,7 @@ next. If you expect characters to get to your device when you print() them, you'll want to autoflush that filehandle. You can use select() -and the C<$|> variable to control autoflushing (see L +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?''): @@ -383,11 +383,11 @@ not an issue with C. You have to be prepared to "reap" the child process when it finishes. $SIG{CHLD} = sub { wait }; - + $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 wait() for your +first child, and the init daemon will wait() for your grandchild once it exits. unless ($pid = fork) { @@ -445,8 +445,8 @@ If perl was installed correctly and your shadow library was written properly, the getpw*() 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). +varies from system to system--see L for specifics) and use +pwd_mkdb(8) to install it (see L for more details). =head2 How do I set the time and date? @@ -511,14 +511,14 @@ something like this: 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 -thread ends (see L manpage for more details). +thread ends (see L manpage for more details). For example, you can use this to make sure your filter program managed to finish its output without filling up the disk: END { 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 @@ -556,7 +556,10 @@ syscall(), you can use the syscall 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. +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 +has an interface to the C function, you can inline a bit of C in your +Perl source with Inline::C. =head2 Where do I get the include files to do ioctl() or syscall()? @@ -594,8 +597,8 @@ scripts inherently insecure. Perl gives you a number of options 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, -though (see L). See -L and +though (see L). See +L and L You may also use the IPC::Open3 module (part of the standard perl @@ -783,7 +786,7 @@ Strictly speaking, nothing. Stylistically speaking, it's not a good way to write maintainable code. Perl has several operators for running external commands. Backticks are one; they collect the output from the command for use in your program. The C function is -another; it doesn't do this. +another; it doesn't do this. Writing backticks in your program sends a clear message to the readers of your code that you wanted to collect the output of the command. @@ -944,7 +947,7 @@ 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 -comp.unix.questions FAQ for details. +comp.unix.questions FAQ for details. =back @@ -965,7 +968,7 @@ module for other solutions. =item * -Open /dev/tty and use the TIOCNOTTY ioctl on it. See L +Open /dev/tty and use the TIOCNOTTY ioctl on it. See L for details. Or better yet, you can just use the POSIX::setsid() function, so you don't have to worry about process groups. @@ -1033,9 +1036,15 @@ in L. =head2 How do I use an SQL database? -There are a number of excellent interfaces to SQL databases. See the -DBD::* modules available from http://www.cpan.org/modules/by-module/DBD/ . -A lot of information on this can be found at http://dbi.perl.org/ +The DBI 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, +and others found on CPAN Search: http://search.cpan.org . =head2 How do I make a system() exit on control-C? @@ -1044,7 +1053,7 @@ 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: $rc = system($cmd); - if ($rc & 127) { die "signal death" } + if ($rc & 127) { die "signal death" } =head2 How do I open a file without blocking? @@ -1060,16 +1069,16 @@ sysopen(): =head2 How do I install a module from CPAN? The easiest way is to have a module also named CPAN do it for you. -This module comes with perl version 5.004 and later. +This module comes with perl version 5.004 and later. $ perl -MCPAN -e shell cpan shell -- CPAN exploration and modules installation (v1.59_54) ReadLine support enabled - cpan> install Some::Module + cpan> install Some::Module -To manually install the CPAN module, or any well-behaved CPAN module +To manually install the CPAN module, or any well-behaved CPAN module for that matter, follow these steps: =over 4 @@ -1129,20 +1138,20 @@ In general, you usually want C and a proper Perl module. =head2 How do I keep my own module/library directory? -When you build modules, use the PREFIX option when generating +When you build modules, use the PREFIX and LIB options when generating Makefiles: - perl Makefile.PL PREFIX=/u/mydir/perl + perl Makefile.PL PREFIX=/mydir/perl LIB=/mydir/perl/lib then either set the PERL5LIB environment variable before you run scripts that use the modules/libraries (see L) or say - use lib '/u/mydir/perl'; + use lib '/mydir/perl/lib'; This is almost the same as BEGIN { - unshift(@INC, '/u/mydir/perl'); + unshift(@INC, '/mydir/perl/lib'); } except that the lib module checks for machine-dependent subdirectories. @@ -1154,7 +1163,7 @@ See Perl's L for more information. use lib "$FindBin::Bin"; use your_own_modules; -=head2 How do I add a directory to my include path at runtime? +=head2 How do I add a directory to my include path (@INC) at runtime? Here are the suggested ways of modifying your include path: @@ -1176,7 +1185,7 @@ but other times it is not. Modern programs C instead. =head1 AUTHOR AND COPYRIGHT -Copyright (c) 1997-2002 Tom Christiansen and Nathan Torkington. +Copyright (c) 1997-2003 Tom Christiansen and Nathan Torkington. All rights reserved. This documentation is free; you can redistribute it and/or modify it