1N/A=head1 NAME
1N/A
1N/Aperlfaq8 - System Interaction ($Revision: 1.17 $, $Date: 2003/01/26 17:44:04 $)
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/AThis section of the Perl FAQ covers questions involving operating
1N/Asystem interaction. Topics include interprocess communication (IPC),
1N/Acontrol over the user-interface (keyboard, screen and pointing
1N/Adevices), and most anything else not related to data manipulation.
1N/A
1N/ARead the FAQs and documentation specific to the port of perl to your
1N/Aoperating system (eg, L<perlvms>, L<perlplan9>, ...). These should
1N/Acontain more detailed information on the vagaries of your perl.
1N/A
1N/A=head2 How do I find out which operating system I'm running under?
1N/A
1N/AThe $^O variable ($OSNAME if you use English) contains an indication of
1N/Athe name of the operating system (not its release number) that your perl
1N/Abinary was built for.
1N/A
1N/A=head2 How come exec() doesn't return?
1N/A
1N/ABecause that's what it does: it replaces your currently running
1N/Aprogram with a different one. If you want to keep going (as is
1N/Aprobably the case if you're asking this question) use system()
1N/Ainstead.
1N/A
1N/A=head2 How do I do fancy stuff with the keyboard/screen/mouse?
1N/A
1N/AHow you access/control keyboards, screens, and pointing devices
1N/A("mice") is system-dependent. Try the following modules:
1N/A
1N/A=over 4
1N/A
1N/A=item Keyboard
1N/A
1N/A Term::Cap Standard perl distribution
1N/A Term::ReadKey CPAN
1N/A Term::ReadLine::Gnu CPAN
1N/A Term::ReadLine::Perl CPAN
1N/A Term::Screen CPAN
1N/A
1N/A=item Screen
1N/A
1N/A Term::Cap Standard perl distribution
1N/A Curses CPAN
1N/A Term::ANSIColor CPAN
1N/A
1N/A=item Mouse
1N/A
1N/A Tk CPAN
1N/A
1N/A=back
1N/A
1N/ASome of these specific cases are shown below.
1N/A
1N/A=head2 How do I print something out in color?
1N/A
1N/AIn general, you don't, because you don't know whether
1N/Athe recipient has a color-aware display device. If you
1N/Aknow that they have an ANSI terminal that understands
1N/Acolor, you can use the Term::ANSIColor module from CPAN:
1N/A
1N/A use Term::ANSIColor;
1N/A print color("red"), "Stop!\n", color("reset");
1N/A print color("green"), "Go!\n", color("reset");
1N/A
1N/AOr like this:
1N/A
1N/A use Term::ANSIColor qw(:constants);
1N/A print RED, "Stop!\n", RESET;
1N/A print GREEN, "Go!\n", RESET;
1N/A
1N/A=head2 How do I read just one key without waiting for a return key?
1N/A
1N/AControlling input buffering is a remarkably system-dependent matter.
1N/AOn many systems, you can just use the B<stty> command as shown in
1N/AL<perlfunc/getc>, but as you see, that's already getting you into
1N/Aportability snags.
1N/A
1N/A open(TTY, "+</dev/tty") or die "no tty: $!";
1N/A system "stty cbreak </dev/tty >/dev/tty 2>&1";
1N/A $key = getc(TTY); # perhaps this works
1N/A # OR ELSE
1N/A sysread(TTY, $key, 1); # probably this does
1N/A system "stty -cbreak </dev/tty >/dev/tty 2>&1";
1N/A
1N/AThe Term::ReadKey module from CPAN offers an easy-to-use interface that
1N/Ashould be more efficient than shelling out to B<stty> for each key.
1N/AIt even includes limited support for Windows.
1N/A
1N/A use Term::ReadKey;
1N/A ReadMode('cbreak');
1N/A $key = ReadKey(0);
1N/A ReadMode('normal');
1N/A
1N/AHowever, using the code requires that you have a working C compiler
1N/Aand can use it to build and install a CPAN module. Here's a solution
1N/Ausing the standard POSIX module, which is already on your systems
1N/A(assuming your system supports POSIX).
1N/A
1N/A use HotKey;
1N/A $key = readkey();
1N/A
1N/AAnd here's the HotKey module, which hides the somewhat mystifying calls
1N/Ato manipulate the POSIX termios structures.
1N/A
1N/A # HotKey.pm
1N/A package HotKey;
1N/A
1N/A @ISA = qw(Exporter);
1N/A @EXPORT = qw(cbreak cooked readkey);
1N/A
1N/A use strict;
1N/A use POSIX qw(:termios_h);
1N/A my ($term, $oterm, $echo, $noecho, $fd_stdin);
1N/A
1N/A $fd_stdin = fileno(STDIN);
1N/A $term = POSIX::Termios->new();
1N/A $term->getattr($fd_stdin);
1N/A $oterm = $term->getlflag();
1N/A
1N/A $echo = ECHO | ECHOK | ICANON;
1N/A $noecho = $oterm & ~$echo;
1N/A
1N/A sub cbreak {
1N/A $term->setlflag($noecho); # ok, so i don't want echo either
1N/A $term->setcc(VTIME, 1);
1N/A $term->setattr($fd_stdin, TCSANOW);
1N/A }
1N/A
1N/A sub cooked {
1N/A $term->setlflag($oterm);
1N/A $term->setcc(VTIME, 0);
1N/A $term->setattr($fd_stdin, TCSANOW);
1N/A }
1N/A
1N/A sub readkey {
1N/A my $key = '';
1N/A cbreak();
1N/A sysread(STDIN, $key, 1);
1N/A cooked();
1N/A return $key;
1N/A }
1N/A
1N/A END { cooked() }
1N/A
1N/A 1;
1N/A
1N/A=head2 How do I check whether input is ready on the keyboard?
1N/A
1N/AThe easiest way to do this is to read a key in nonblocking mode with the
1N/ATerm::ReadKey module from CPAN, passing it an argument of -1 to indicate
1N/Anot to block:
1N/A
1N/A use Term::ReadKey;
1N/A
1N/A ReadMode('cbreak');
1N/A
1N/A if (defined ($char = ReadKey(-1)) ) {
1N/A # input was waiting and it was $char
1N/A } else {
1N/A # no input was waiting
1N/A }
1N/A
1N/A ReadMode('normal'); # restore normal tty settings
1N/A
1N/A=head2 How do I clear the screen?
1N/A
1N/AIf you only have do so infrequently, use C<system>:
1N/A
1N/A system("clear");
1N/A
1N/AIf you have to do this a lot, save the clear string
1N/Aso you can print it 100 times without calling a program
1N/A100 times:
1N/A
1N/A $clear_string = `clear`;
1N/A print $clear_string;
1N/A
1N/AIf you're planning on doing other screen manipulations, like cursor
1N/Apositions, etc, you might wish to use Term::Cap module:
1N/A
1N/A use Term::Cap;
1N/A $terminal = Term::Cap->Tgetent( {OSPEED => 9600} );
1N/A $clear_string = $terminal->Tputs('cl');
1N/A
1N/A=head2 How do I get the screen size?
1N/A
1N/AIf you have Term::ReadKey module installed from CPAN,
1N/Ayou can use it to fetch the width and height in characters
1N/Aand in pixels:
1N/A
1N/A use Term::ReadKey;
1N/A ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
1N/A
1N/AThis is more portable than the raw C<ioctl>, but not as
1N/Aillustrative:
1N/A
1N/A require 'sys/ioctl.ph';
1N/A die "no TIOCGWINSZ " unless defined &TIOCGWINSZ;
1N/A open(TTY, "+</dev/tty") or die "No tty: $!";
1N/A unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) {
1N/A die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
1N/A }
1N/A ($row, $col, $xpixel, $ypixel) = unpack('S4', $winsize);
1N/A print "(row,col) = ($row,$col)";
1N/A print " (xpixel,ypixel) = ($xpixel,$ypixel)" if $xpixel || $ypixel;
1N/A print "\n";
1N/A
1N/A=head2 How do I ask the user for a password?
1N/A
1N/A(This question has nothing to do with the web. See a different
1N/AFAQ for that.)
1N/A
1N/AThere's an example of this in L<perlfunc/crypt>). First, you put the
1N/Aterminal into "no echo" mode, then just read the password normally.
1N/AYou may do this with an old-style ioctl() function, POSIX terminal
1N/Acontrol (see L<POSIX> or its documentation the Camel Book), or a call
1N/Ato the B<stty> program, with varying degrees of portability.
1N/A
1N/AYou can also do this for most systems using the Term::ReadKey module
1N/Afrom CPAN, which is easier to use and in theory more portable.
1N/A
1N/A use Term::ReadKey;
1N/A
1N/A ReadMode('noecho');
1N/A $password = ReadLine(0);
1N/A
1N/A=head2 How do I read and write the serial port?
1N/A
1N/AThis depends on which operating system your program is running on. In
1N/Athe case of Unix, the serial ports will be accessible through files in
1N/A/dev; on other systems, device names will doubtless differ.
1N/ASeveral problem areas common to all device interaction are the
1N/Afollowing:
1N/A
1N/A=over 4
1N/A
1N/A=item lockfiles
1N/A
1N/AYour system may use lockfiles to control multiple access. Make sure
1N/Ayou follow the correct protocol. Unpredictable behavior can result
1N/Afrom multiple processes reading from one device.
1N/A
1N/A=item open mode
1N/A
1N/AIf you expect to use both read and write operations on the device,
1N/Ayou'll have to open it for update (see L<perlfunc/"open"> for
1N/Adetails). You may wish to open it without running the risk of
1N/Ablocking by using sysopen() and C<O_RDWR|O_NDELAY|O_NOCTTY> from the
1N/AFcntl module (part of the standard perl distribution). See
1N/AL<perlfunc/"sysopen"> for more on this approach.
1N/A
1N/A=item end of line
1N/A
1N/ASome devices will be expecting a "\r" at the end of each line rather
1N/Athan a "\n". In some ports of perl, "\r" and "\n" are different from
1N/Atheir usual (Unix) ASCII values of "\012" and "\015". You may have to
1N/Agive the numeric values you want directly, using octal ("\015"), hex
1N/A("0x0D"), or as a control-character specification ("\cM").
1N/A
1N/A print DEV "atv1\012"; # wrong, for some devices
1N/A print DEV "atv1\015"; # right, for some devices
1N/A
1N/AEven though with normal text files a "\n" will do the trick, there is
1N/Astill no unified scheme for terminating a line that is portable
1N/Abetween Unix, DOS/Win, and Macintosh, except to terminate I<ALL> line
1N/Aends with "\015\012", and strip what you don't need from the output.
1N/AThis applies especially to socket I/O and autoflushing, discussed
1N/Anext.
1N/A
1N/A=item flushing output
1N/A
1N/AIf you expect characters to get to your device when you print() them,
1N/Ayou'll want to autoflush that filehandle. You can use select()
1N/Aand the C<$|> variable to control autoflushing (see L<perlvar/$E<verbar>>
1N/Aand L<perlfunc/select>, or L<perlfaq5>, ``How do I flush/unbuffer an
1N/Aoutput filehandle? Why must I do this?''):
1N/A
1N/A $oldh = select(DEV);
1N/A $| = 1;
1N/A select($oldh);
1N/A
1N/AYou'll also see code that does this without a temporary variable, as in
1N/A
1N/A select((select(DEV), $| = 1)[0]);
1N/A
1N/AOr if you don't mind pulling in a few thousand lines
1N/Aof code just because you're afraid of a little $| variable:
1N/A
1N/A use IO::Handle;
1N/A DEV->autoflush(1);
1N/A
1N/AAs mentioned in the previous item, this still doesn't work when using
1N/Asocket I/O between Unix and Macintosh. You'll need to hard code your
1N/Aline terminators, in that case.
1N/A
1N/A=item non-blocking input
1N/A
1N/AIf you are doing a blocking read() or sysread(), you'll have to
1N/Aarrange for an alarm handler to provide a timeout (see
1N/AL<perlfunc/alarm>). If you have a non-blocking open, you'll likely
1N/Ahave a non-blocking read, which means you may have to use a 4-arg
1N/Aselect() to determine whether I/O is ready on that device (see
1N/AL<perlfunc/"select">.
1N/A
1N/A=back
1N/A
1N/AWhile trying to read from his caller-id box, the notorious Jamie Zawinski
1N/A<jwz@netscape.com>, after much gnashing of teeth and fighting with sysread,
1N/Asysopen, POSIX's tcgetattr business, and various other functions that
1N/Ago bump in the night, finally came up with this:
1N/A
1N/A sub open_modem {
1N/A use IPC::Open2;
1N/A my $stty = `/bin/stty -g`;
1N/A open2( \*MODEM_IN, \*MODEM_OUT, "cu -l$modem_device -s2400 2>&1");
1N/A # starting cu hoses /dev/tty's stty settings, even when it has
1N/A # been opened on a pipe...
1N/A system("/bin/stty $stty");
1N/A $_ = <MODEM_IN>;
1N/A chomp;
1N/A if ( !m/^Connected/ ) {
1N/A print STDERR "$0: cu printed `$_' instead of `Connected'\n";
1N/A }
1N/A }
1N/A
1N/A=head2 How do I decode encrypted password files?
1N/A
1N/AYou spend lots and lots of money on dedicated hardware, but this is
1N/Abound to get you talked about.
1N/A
1N/ASeriously, you can't if they are Unix password files--the Unix
1N/Apassword system employs one-way encryption. It's more like hashing than
1N/Aencryption. The best you can check is whether something else hashes to
1N/Athe same string. You can't turn a hash back into the original string.
1N/APrograms like Crack
1N/Acan forcibly (and intelligently) try to guess passwords, but don't
1N/A(can't) guarantee quick success.
1N/A
1N/AIf you're worried about users selecting bad passwords, you should
1N/Aproactively check when they try to change their password (by modifying
1N/Apasswd(1), for example).
1N/A
1N/A=head2 How do I start a process in the background?
1N/A
1N/ASeveral modules can start other processes that do not block
1N/Ayour Perl program. You can use IPC::Open3, Parallel::Jobs,
1N/AIPC::Run, and some of the POE modules. See CPAN for more
1N/Adetails.
1N/A
1N/AYou could also use
1N/A
1N/A system("cmd &")
1N/A
1N/Aor you could use fork as documented in L<perlfunc/"fork">, with
1N/Afurther examples in L<perlipc>. Some things to be aware of, if you're
1N/Aon a Unix-like system:
1N/A
1N/A=over 4
1N/A
1N/A=item STDIN, STDOUT, and STDERR are shared
1N/A
1N/ABoth the main process and the backgrounded one (the "child" process)
1N/Ashare the same STDIN, STDOUT and STDERR filehandles. If both try to
1N/Aaccess them at once, strange things can happen. You may want to close
1N/Aor reopen these for the child. You can get around this with
1N/AC<open>ing a pipe (see L<perlfunc/"open">) but on some systems this
1N/Ameans that the child process cannot outlive the parent.
1N/A
1N/A=item Signals
1N/A
1N/AYou'll have to catch the SIGCHLD signal, and possibly SIGPIPE too.
1N/ASIGCHLD is sent when the backgrounded process finishes. SIGPIPE is
1N/Asent when you write to a filehandle whose child process has closed (an
1N/Auntrapped SIGPIPE can cause your program to silently die). This is
1N/Anot an issue with C<system("cmd&")>.
1N/A
1N/A=item Zombies
1N/A
1N/AYou have to be prepared to "reap" the child process when it finishes.
1N/A
1N/A $SIG{CHLD} = sub { wait };
1N/A
1N/A $SIG{CHLD} = 'IGNORE';
1N/A
1N/AYou can also use a double fork. You immediately wait() for your
1N/Afirst child, and the init daemon will wait() for your grandchild once
1N/Ait exits.
1N/A
1N/A unless ($pid = fork) {
1N/A unless (fork) {
1N/A exec "what you really wanna do";
1N/A die "exec failed!";
1N/A }
1N/A exit 0;
1N/A }
1N/A waitpid($pid,0);
1N/A
1N/A
1N/ASee L<perlipc/"Signals"> for other examples of code to do this.
1N/AZombies are not an issue with C<system("prog &")>.
1N/A
1N/A=back
1N/A
1N/A=head2 How do I trap control characters/signals?
1N/A
1N/AYou don't actually "trap" a control character. Instead, that character
1N/Agenerates a signal which is sent to your terminal's currently
1N/Aforegrounded process group, which you then trap in your process.
1N/ASignals are documented in L<perlipc/"Signals"> and the
1N/Asection on ``Signals'' in the Camel.
1N/A
1N/ABe warned that very few C libraries are re-entrant. Therefore, if you
1N/Aattempt to print() in a handler that got invoked during another stdio
1N/Aoperation your internal structures will likely be in an
1N/Ainconsistent state, and your program will dump core. You can
1N/Asometimes avoid this by using syswrite() instead of print().
1N/A
1N/AUnless you're exceedingly careful, the only safe things to do inside a
1N/Asignal handler are (1) set a variable and (2) exit. In the first case,
1N/Ayou should only set a variable in such a way that malloc() is not
1N/Acalled (eg, by setting a variable that already has a value).
1N/A
1N/AFor example:
1N/A
1N/A $Interrupted = 0; # to ensure it has a value
1N/A $SIG{INT} = sub {
1N/A $Interrupted++;
1N/A syswrite(STDERR, "ouch\n", 5);
1N/A }
1N/A
1N/AHowever, because syscalls restart by default, you'll find that if
1N/Ayou're in a "slow" call, such as <FH>, read(), connect(), or
1N/Await(), that the only way to terminate them is by "longjumping" out;
1N/Athat is, by raising an exception. See the time-out handler for a
1N/Ablocking flock() in L<perlipc/"Signals"> or the section on ``Signals''
1N/Ain the Camel book.
1N/A
1N/A=head2 How do I modify the shadow password file on a Unix system?
1N/A
1N/AIf perl was installed correctly and your shadow library was written
1N/Aproperly, the getpw*() functions described in L<perlfunc> should in
1N/Atheory provide (read-only) access to entries in the shadow password
1N/Afile. To change the file, make a new shadow password file (the format
1N/Avaries from system to system--see L<passwd> for specifics) and use
1N/Apwd_mkdb(8) to install it (see L<pwd_mkdb> for more details).
1N/A
1N/A=head2 How do I set the time and date?
1N/A
1N/AAssuming you're running under sufficient permissions, you should be
1N/Aable to set the system-wide date and time by running the date(1)
1N/Aprogram. (There is no way to set the time and date on a per-process
1N/Abasis.) This mechanism will work for Unix, MS-DOS, Windows, and NT;
1N/Athe VMS equivalent is C<set time>.
1N/A
1N/AHowever, if all you want to do is change your time zone, you can
1N/Aprobably get away with setting an environment variable:
1N/A
1N/A $ENV{TZ} = "MST7MDT"; # unixish
1N/A $ENV{'SYS$TIMEZONE_DIFFERENTIAL'}="-5" # vms
1N/A system "trn comp.lang.perl.misc";
1N/A
1N/A=head2 How can I sleep() or alarm() for under a second?
1N/A
1N/AIf you want finer granularity than the 1 second that the sleep()
1N/Afunction provides, the easiest way is to use the select() function as
1N/Adocumented in L<perlfunc/"select">. Try the Time::HiRes and
1N/Athe BSD::Itimer modules (available from CPAN, and starting from
1N/APerl 5.8 Time::HiRes is part of the standard distribution).
1N/A
1N/A=head2 How can I measure time under a second?
1N/A
1N/AIn general, you may not be able to. The Time::HiRes module (available
1N/Afrom CPAN, and starting from Perl 5.8 part of the standard distribution)
1N/Aprovides this functionality for some systems.
1N/A
1N/AIf your system supports both the syscall() function in Perl as well as
1N/Aa system call like gettimeofday(2), then you may be able to do
1N/Asomething like this:
1N/A
1N/A require 'sys/syscall.ph';
1N/A
1N/A $TIMEVAL_T = "LL";
1N/A
1N/A $done = $start = pack($TIMEVAL_T, ());
1N/A
1N/A syscall(&SYS_gettimeofday, $start, 0) != -1
1N/A or die "gettimeofday: $!";
1N/A
1N/A ##########################
1N/A # DO YOUR OPERATION HERE #
1N/A ##########################
1N/A
1N/A syscall( &SYS_gettimeofday, $done, 0) != -1
1N/A or die "gettimeofday: $!";
1N/A
1N/A @start = unpack($TIMEVAL_T, $start);
1N/A @done = unpack($TIMEVAL_T, $done);
1N/A
1N/A # fix microseconds
1N/A for ($done[1], $start[1]) { $_ /= 1_000_000 }
1N/A
1N/A $delta_time = sprintf "%.4f", ($done[0] + $done[1] )
1N/A -
1N/A ($start[0] + $start[1] );
1N/A
1N/A=head2 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
1N/A
1N/ARelease 5 of Perl added the END block, which can be used to simulate
1N/Aatexit(). Each package's END block is called when the program or
1N/Athread ends (see L<perlmod> manpage for more details).
1N/A
1N/AFor example, you can use this to make sure your filter program
1N/Amanaged to finish its output without filling up the disk:
1N/A
1N/A END {
1N/A close(STDOUT) || die "stdout close failed: $!";
1N/A }
1N/A
1N/AThe END block isn't called when untrapped signals kill the program,
1N/Athough, so if you use END blocks you should also use
1N/A
1N/A use sigtrap qw(die normal-signals);
1N/A
1N/APerl's exception-handling mechanism is its eval() operator. You can
1N/Ause eval() as setjmp and die() as longjmp. For details of this, see
1N/Athe section on signals, especially the time-out handler for a blocking
1N/Aflock() in L<perlipc/"Signals"> or the section on ``Signals'' in
1N/Athe Camel Book.
1N/A
1N/AIf exception handling is all you're interested in, try the
1N/Aexceptions.pl library (part of the standard perl distribution).
1N/A
1N/AIf you want the atexit() syntax (and an rmexit() as well), try the
1N/AAtExit module available from CPAN.
1N/A
1N/A=head2 Why doesn't my sockets program work under System V (Solaris)? What does the error message "Protocol not supported" mean?
1N/A
1N/ASome Sys-V based systems, notably Solaris 2.X, redefined some of the
1N/Astandard socket constants. Since these were constant across all
1N/Aarchitectures, they were often hardwired into perl code. The proper
1N/Away to deal with this is to "use Socket" to get the correct values.
1N/A
1N/ANote that even though SunOS and Solaris are binary compatible, these
1N/Avalues are different. Go figure.
1N/A
1N/A=head2 How can I call my system's unique C functions from Perl?
1N/A
1N/AIn most cases, you write an external module to do it--see the answer
1N/Ato "Where can I learn about linking C with Perl? [h2xs, xsubpp]".
1N/AHowever, if the function is a system call, and your system supports
1N/Asyscall(), you can use the syscall function (documented in
1N/AL<perlfunc>).
1N/A
1N/ARemember to check the modules that came with your distribution, and
1N/ACPAN as well---someone may already have written a module to do it. On
1N/AWindows, try Win32::API. On Macs, try Mac::Carbon. If no module
1N/Ahas an interface to the C function, you can inline a bit of C in your
1N/APerl source with Inline::C.
1N/A
1N/A=head2 Where do I get the include files to do ioctl() or syscall()?
1N/A
1N/AHistorically, these would be generated by the h2ph tool, part of the
1N/Astandard perl distribution. This program converts cpp(1) directives
1N/Ain C header files to files containing subroutine definitions, like
1N/A&SYS_getitimer, which you can use as arguments to your functions.
1N/AIt doesn't work perfectly, but it usually gets most of the job done.
1N/ASimple files like F<errno.h>, F<syscall.h>, and F<socket.h> were fine,
1N/Abut the hard ones like F<ioctl.h> nearly always need to hand-edited.
1N/AHere's how to install the *.ph files:
1N/A
1N/A 1. become super-user
1N/A 2. cd /usr/include
1N/A 3. h2ph *.h */*.h
1N/A
1N/AIf your system supports dynamic loading, for reasons of portability and
1N/Asanity you probably ought to use h2xs (also part of the standard perl
1N/Adistribution). This tool converts C header files to Perl extensions.
1N/ASee L<perlxstut> for how to get started with h2xs.
1N/A
1N/AIf your system doesn't support dynamic loading, you still probably
1N/Aought to use h2xs. See L<perlxstut> and L<ExtUtils::MakeMaker> for
1N/Amore information (in brief, just use B<make perl> instead of a plain
1N/AB<make> to rebuild perl with a new static extension).
1N/A
1N/A=head2 Why do setuid perl scripts complain about kernel problems?
1N/A
1N/ASome operating systems have bugs in the kernel that make setuid
1N/Ascripts inherently insecure. Perl gives you a number of options
1N/A(described in L<perlsec>) to work around such systems.
1N/A
1N/A=head2 How can I open a pipe both to and from a command?
1N/A
1N/AThe IPC::Open2 module (part of the standard perl distribution) is an
1N/Aeasy-to-use approach that internally uses pipe(), fork(), and exec() to do
1N/Athe job. Make sure you read the deadlock warnings in its documentation,
1N/Athough (see L<IPC::Open2>). See
1N/AL<perlipc/"Bidirectional Communication with Another Process"> and
1N/AL<perlipc/"Bidirectional Communication with Yourself">
1N/A
1N/AYou may also use the IPC::Open3 module (part of the standard perl
1N/Adistribution), but be warned that it has a different order of
1N/Aarguments from IPC::Open2 (see L<IPC::Open3>).
1N/A
1N/A=head2 Why can't I get the output of a command with system()?
1N/A
1N/AYou're confusing the purpose of system() and backticks (``). system()
1N/Aruns a command and returns exit status information (as a 16 bit value:
1N/Athe low 7 bits are the signal the process died from, if any, and
1N/Athe high 8 bits are the actual exit value). Backticks (``) run a
1N/Acommand and return what it sent to STDOUT.
1N/A
1N/A $exit_status = system("mail-users");
1N/A $output_string = `ls`;
1N/A
1N/A=head2 How can I capture STDERR from an external command?
1N/A
1N/AThere are three basic ways of running external commands:
1N/A
1N/A system $cmd; # using system()
1N/A $output = `$cmd`; # using backticks (``)
1N/A open (PIPE, "cmd |"); # using open()
1N/A
1N/AWith system(), both STDOUT and STDERR will go the same place as the
1N/Ascript's STDOUT and STDERR, unless the system() command redirects them.
1N/ABackticks and open() read B<only> the STDOUT of your command.
1N/A
1N/AYou can also use the open3() function from IPC::Open3. Benjamin
1N/AGoldberg provides some sample code:
1N/A
1N/ATo capture a program's STDOUT, but discard its STDERR:
1N/A
1N/A use IPC::Open3;
1N/A use File::Spec;
1N/A use Symbol qw(gensym);
1N/A open(NULL, ">", File::Spec->devnull);
1N/A my $pid = open3(gensym, \*PH, ">&NULL", "cmd");
1N/A while( <PH> ) { }
1N/A waitpid($pid, 0);
1N/A
1N/ATo capture a program's STDERR, but discard its STDOUT:
1N/A
1N/A use IPC::Open3;
1N/A use File::Spec;
1N/A use Symbol qw(gensym);
1N/A open(NULL, ">", File::Spec->devnull);
1N/A my $pid = open3(gensym, ">&NULL", \*PH, "cmd");
1N/A while( <PH> ) { }
1N/A waitpid($pid, 0);
1N/A
1N/ATo capture a program's STDERR, and let its STDOUT go to our own STDERR:
1N/A
1N/A use IPC::Open3;
1N/A use Symbol qw(gensym);
1N/A my $pid = open3(gensym, ">&STDERR", \*PH, "cmd");
1N/A while( <PH> ) { }
1N/A waitpid($pid, 0);
1N/A
1N/ATo read both a command's STDOUT and its STDERR separately, you can
1N/Aredirect them to temp files, let the command run, then read the temp
1N/Afiles:
1N/A
1N/A use IPC::Open3;
1N/A use Symbol qw(gensym);
1N/A use IO::File;
1N/A local *CATCHOUT = IO::File->new_tempfile;
1N/A local *CATCHERR = IO::File->new_tempfile;
1N/A my $pid = open3(gensym, ">&CATCHOUT", ">&CATCHERR", "cmd");
1N/A waitpid($pid, 0);
1N/A seek $_, 0, 0 for \*CATCHOUT, \*CATCHERR;
1N/A while( <CATCHOUT> ) {}
1N/A while( <CATCHERR> ) {}
1N/A
1N/ABut there's no real need for *both* to be tempfiles... the following
1N/Ashould work just as well, without deadlocking:
1N/A
1N/A use IPC::Open3;
1N/A use Symbol qw(gensym);
1N/A use IO::File;
1N/A local *CATCHERR = IO::File->new_tempfile;
1N/A my $pid = open3(gensym, \*CATCHOUT, ">&CATCHERR", "cmd");
1N/A while( <CATCHOUT> ) {}
1N/A waitpid($pid, 0);
1N/A seek CATCHERR, 0, 0;
1N/A while( <CATCHERR> ) {}
1N/A
1N/AAnd it'll be faster, too, since we can begin processing the program's
1N/Astdout immediately, rather than waiting for the program to finish.
1N/A
1N/AWith any of these, you can change file descriptors before the call:
1N/A
1N/A open(STDOUT, ">logfile");
1N/A system("ls");
1N/A
1N/Aor you can use Bourne shell file-descriptor redirection:
1N/A
1N/A $output = `$cmd 2>some_file`;
1N/A open (PIPE, "cmd 2>some_file |");
1N/A
1N/AYou can also use file-descriptor redirection to make STDERR a
1N/Aduplicate of STDOUT:
1N/A
1N/A $output = `$cmd 2>&1`;
1N/A open (PIPE, "cmd 2>&1 |");
1N/A
1N/ANote that you I<cannot> simply open STDERR to be a dup of STDOUT
1N/Ain your Perl program and avoid calling the shell to do the redirection.
1N/AThis doesn't work:
1N/A
1N/A open(STDERR, ">&STDOUT");
1N/A $alloutput = `cmd args`; # stderr still escapes
1N/A
1N/AThis fails because the open() makes STDERR go to where STDOUT was
1N/Agoing at the time of the open(). The backticks then make STDOUT go to
1N/Aa string, but don't change STDERR (which still goes to the old
1N/ASTDOUT).
1N/A
1N/ANote that you I<must> use Bourne shell (sh(1)) redirection syntax in
1N/Abackticks, not csh(1)! Details on why Perl's system() and backtick
1N/Aand pipe opens all use the Bourne shell are in the
1N/AF<versus/csh.whynot> article in the "Far More Than You Ever Wanted To
1N/AKnow" collection in http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz . To
1N/Acapture a command's STDERR and STDOUT together:
1N/A
1N/A $output = `cmd 2>&1`; # either with backticks
1N/A $pid = open(PH, "cmd 2>&1 |"); # or with an open pipe
1N/A while (<PH>) { } # plus a read
1N/A
1N/ATo capture a command's STDOUT but discard its STDERR:
1N/A
1N/A $output = `cmd 2>/dev/null`; # either with backticks
1N/A $pid = open(PH, "cmd 2>/dev/null |"); # or with an open pipe
1N/A while (<PH>) { } # plus a read
1N/A
1N/ATo capture a command's STDERR but discard its STDOUT:
1N/A
1N/A $output = `cmd 2>&1 1>/dev/null`; # either with backticks
1N/A $pid = open(PH, "cmd 2>&1 1>/dev/null |"); # or with an open pipe
1N/A while (<PH>) { } # plus a read
1N/A
1N/ATo exchange a command's STDOUT and STDERR in order to capture the STDERR
1N/Abut leave its STDOUT to come out our old STDERR:
1N/A
1N/A $output = `cmd 3>&1 1>&2 2>&3 3>&-`; # either with backticks
1N/A $pid = open(PH, "cmd 3>&1 1>&2 2>&3 3>&-|");# or with an open pipe
1N/A while (<PH>) { } # plus a read
1N/A
1N/ATo read both a command's STDOUT and its STDERR separately, it's easiest
1N/Ato redirect them separately to files, and then read from those files
1N/Awhen the program is done:
1N/A
1N/A system("program args 1>program.stdout 2>program.stderr");
1N/A
1N/AOrdering is important in all these examples. That's because the shell
1N/Aprocesses file descriptor redirections in strictly left to right order.
1N/A
1N/A system("prog args 1>tmpfile 2>&1");
1N/A system("prog args 2>&1 1>tmpfile");
1N/A
1N/AThe first command sends both standard out and standard error to the
1N/Atemporary file. The second command sends only the old standard output
1N/Athere, and the old standard error shows up on the old standard out.
1N/A
1N/A=head2 Why doesn't open() return an error when a pipe open fails?
1N/A
1N/AIf the second argument to a piped open() contains shell
1N/Ametacharacters, perl fork()s, then exec()s a shell to decode the
1N/Ametacharacters and eventually run the desired program. If the program
1N/Acouldn't be run, it's the shell that gets the message, not Perl. All
1N/Ayour Perl program can find out is whether the shell itself could be
1N/Asuccessfully started. You can still capture the shell's STDERR and
1N/Acheck it for error messages. See L<"How can I capture STDERR from an
1N/Aexternal command?"> elsewhere in this document, or use the
1N/AIPC::Open3 module.
1N/A
1N/AIf there are no shell metacharacters in the argument of open(), Perl
1N/Aruns the command directly, without using the shell, and can correctly
1N/Areport whether the command started.
1N/A
1N/A=head2 What's wrong with using backticks in a void context?
1N/A
1N/AStrictly speaking, nothing. Stylistically speaking, it's not a good
1N/Away to write maintainable code. Perl has several operators for
1N/Arunning external commands. Backticks are one; they collect the output
1N/Afrom the command for use in your program. The C<system> function is
1N/Aanother; it doesn't do this.
1N/A
1N/AWriting backticks in your program sends a clear message to the readers
1N/Aof your code that you wanted to collect the output of the command.
1N/AWhy send a clear message that isn't true?
1N/A
1N/AConsider this line:
1N/A
1N/A `cat /etc/termcap`;
1N/A
1N/AYou forgot to check C<$?> to see whether the program even ran
1N/Acorrectly. Even if you wrote
1N/A
1N/A print `cat /etc/termcap`;
1N/A
1N/Athis code could and probably should be written as
1N/A
1N/A system("cat /etc/termcap") == 0
1N/A or die "cat program failed!";
1N/A
1N/Awhich will get the output quickly (as it is generated, instead of only
1N/Aat the end) and also check the return value.
1N/A
1N/Asystem() also provides direct control over whether shell wildcard
1N/Aprocessing may take place, whereas backticks do not.
1N/A
1N/A=head2 How can I call backticks without shell processing?
1N/A
1N/AThis is a bit tricky. You can't simply write the command
1N/Alike this:
1N/A
1N/A @ok = `grep @opts '$search_string' @filenames`;
1N/A
1N/AAs of Perl 5.8.0, you can use open() with multiple arguments.
1N/AJust like the list forms of system() and exec(), no shell
1N/Aescapes happen.
1N/A
1N/A open( GREP, "-|", 'grep', @opts, $search_string, @filenames );
1N/A chomp(@ok = <GREP>);
1N/A close GREP;
1N/A
1N/AYou can also:
1N/A
1N/A my @ok = ();
1N/A if (open(GREP, "-|")) {
1N/A while (<GREP>) {
1N/A chomp;
1N/A push(@ok, $_);
1N/A }
1N/A close GREP;
1N/A } else {
1N/A exec 'grep', @opts, $search_string, @filenames;
1N/A }
1N/A
1N/AJust as with system(), no shell escapes happen when you exec() a list.
1N/AFurther examples of this can be found in L<perlipc/"Safe Pipe Opens">.
1N/A
1N/ANote that if you're use Microsoft, no solution to this vexing issue
1N/Ais even possible. Even if Perl were to emulate fork(), you'd still
1N/Abe stuck, because Microsoft does not have a argc/argv-style API.
1N/A
1N/A=head2 Why can't my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS-DOS)?
1N/A
1N/ASome stdio's set error and eof flags that need clearing. The
1N/APOSIX module defines clearerr() that you can use. That is the
1N/Atechnically correct way to do it. Here are some less reliable
1N/Aworkarounds:
1N/A
1N/A=over 4
1N/A
1N/A=item 1
1N/A
1N/ATry keeping around the seekpointer and go there, like this:
1N/A
1N/A $where = tell(LOG);
1N/A seek(LOG, $where, 0);
1N/A
1N/A=item 2
1N/A
1N/AIf that doesn't work, try seeking to a different part of the file and
1N/Athen back.
1N/A
1N/A=item 3
1N/A
1N/AIf that doesn't work, try seeking to a different part of
1N/Athe file, reading something, and then seeking back.
1N/A
1N/A=item 4
1N/A
1N/AIf that doesn't work, give up on your stdio package and use sysread.
1N/A
1N/A=back
1N/A
1N/A=head2 How can I convert my shell script to perl?
1N/A
1N/ALearn Perl and rewrite it. Seriously, there's no simple converter.
1N/AThings that are awkward to do in the shell are easy to do in Perl, and
1N/Athis very awkwardness is what would make a shell->perl converter
1N/Anigh-on impossible to write. By rewriting it, you'll think about what
1N/Ayou're really trying to do, and hopefully will escape the shell's
1N/Apipeline datastream paradigm, which while convenient for some matters,
1N/Acauses many inefficiencies.
1N/A
1N/A=head2 Can I use perl to run a telnet or ftp session?
1N/A
1N/ATry the Net::FTP, TCP::Client, and Net::Telnet modules (available from
1N/ACPAN). http://www.cpan.org/scripts/netstuff/telnet.emul.shar
1N/Awill also help for emulating the telnet protocol, but Net::Telnet is
1N/Aquite probably easier to use..
1N/A
1N/AIf all you want to do is pretend to be telnet but don't need
1N/Athe initial telnet handshaking, then the standard dual-process
1N/Aapproach will suffice:
1N/A
1N/A use IO::Socket; # new in 5.004
1N/A $handle = IO::Socket::INET->new('www.perl.com:80')
1N/A || die "can't connect to port 80 on www.perl.com: $!";
1N/A $handle->autoflush(1);
1N/A if (fork()) { # XXX: undef means failure
1N/A select($handle);
1N/A print while <STDIN>; # everything from stdin to socket
1N/A } else {
1N/A print while <$handle>; # everything from socket to stdout
1N/A }
1N/A close $handle;
1N/A exit;
1N/A
1N/A=head2 How can I write expect in Perl?
1N/A
1N/AOnce upon a time, there was a library called chat2.pl (part of the
1N/Astandard perl distribution), which never really got finished. If you
1N/Afind it somewhere, I<don't use it>. These days, your best bet is to
1N/Alook at the Expect module available from CPAN, which also requires two
1N/Aother modules from CPAN, IO::Pty and IO::Stty.
1N/A
1N/A=head2 Is there a way to hide perl's command line from programs such as "ps"?
1N/A
1N/AFirst of all note that if you're doing this for security reasons (to
1N/Aavoid people seeing passwords, for example) then you should rewrite
1N/Ayour program so that critical information is never given as an
1N/Aargument. Hiding the arguments won't make your program completely
1N/Asecure.
1N/A
1N/ATo actually alter the visible command line, you can assign to the
1N/Avariable $0 as documented in L<perlvar>. This won't work on all
1N/Aoperating systems, though. Daemon programs like sendmail place their
1N/Astate there, as in:
1N/A
1N/A $0 = "orcus [accepting connections]";
1N/A
1N/A=head2 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?
1N/A
1N/A=over 4
1N/A
1N/A=item Unix
1N/A
1N/AIn the strictest sense, it can't be done--the script executes as a
1N/Adifferent process from the shell it was started from. Changes to a
1N/Aprocess are not reflected in its parent--only in any children
1N/Acreated after the change. There is shell magic that may allow you to
1N/Afake it by eval()ing the script's output in your shell; check out the
1N/Acomp.unix.questions FAQ for details.
1N/A
1N/A=back
1N/A
1N/A=head2 How do I close a process's filehandle without waiting for it to complete?
1N/A
1N/AAssuming your system supports such things, just send an appropriate signal
1N/Ato the process (see L<perlfunc/"kill">). It's common to first send a TERM
1N/Asignal, wait a little bit, and then send a KILL signal to finish it off.
1N/A
1N/A=head2 How do I fork a daemon process?
1N/A
1N/AIf by daemon process you mean one that's detached (disassociated from
1N/Aits tty), then the following process is reported to work on most
1N/AUnixish systems. Non-Unix users should check their Your_OS::Process
1N/Amodule for other solutions.
1N/A
1N/A=over 4
1N/A
1N/A=item *
1N/A
1N/AOpen /dev/tty and use the TIOCNOTTY ioctl on it. See L<tty>
1N/Afor details. Or better yet, you can just use the POSIX::setsid()
1N/Afunction, so you don't have to worry about process groups.
1N/A
1N/A=item *
1N/A
1N/AChange directory to /
1N/A
1N/A=item *
1N/A
1N/AReopen STDIN, STDOUT, and STDERR so they're not connected to the old
1N/Atty.
1N/A
1N/A=item *
1N/A
1N/ABackground yourself like this:
1N/A
1N/A fork && exit;
1N/A
1N/A=back
1N/A
1N/AThe Proc::Daemon module, available from CPAN, provides a function to
1N/Aperform these actions for you.
1N/A
1N/A=head2 How do I find out if I'm running interactively or not?
1N/A
1N/AGood question. Sometimes C<-t STDIN> and C<-t STDOUT> can give clues,
1N/Asometimes not.
1N/A
1N/A if (-t STDIN && -t STDOUT) {
1N/A print "Now what? ";
1N/A }
1N/A
1N/AOn POSIX systems, you can test whether your own process group matches
1N/Athe current process group of your controlling terminal as follows:
1N/A
1N/A use POSIX qw/getpgrp tcgetpgrp/;
1N/A open(TTY, "/dev/tty") or die $!;
1N/A $tpgrp = tcgetpgrp(fileno(*TTY));
1N/A $pgrp = getpgrp();
1N/A if ($tpgrp == $pgrp) {
1N/A print "foreground\n";
1N/A } else {
1N/A print "background\n";
1N/A }
1N/A
1N/A=head2 How do I timeout a slow event?
1N/A
1N/AUse the alarm() function, probably in conjunction with a signal
1N/Ahandler, as documented in L<perlipc/"Signals"> and the section on
1N/A``Signals'' in the Camel. You may instead use the more flexible
1N/ASys::AlarmCall module available from CPAN.
1N/A
1N/AThe alarm() function is not implemented on all versions of Windows.
1N/ACheck the documentation for your specific version of Perl.
1N/A
1N/A=head2 How do I set CPU limits?
1N/A
1N/AUse the BSD::Resource module from CPAN.
1N/A
1N/A=head2 How do I avoid zombies on a Unix system?
1N/A
1N/AUse the reaper code from L<perlipc/"Signals"> to call wait() when a
1N/ASIGCHLD is received, or else use the double-fork technique described
1N/Ain L<perlfaq8/"How do I start a process in the background?">.
1N/A
1N/A=head2 How do I use an SQL database?
1N/A
1N/AThe DBI module provides an abstract interface to most database
1N/Aservers and types, including Oracle, DB2, Sybase, mysql, Postgresql,
1N/AODBC, and flat files. The DBI module accesses each database type
1N/Athrough a database driver, or DBD. You can see a complete list of
1N/Aavailable drivers on CPAN: http://www.cpan.org/modules/by-module/DBD/ .
1N/AYou can read more about DBI on http://dbi.perl.org .
1N/A
1N/AOther modules provide more specific access: Win32::ODBC, Alzabo, iodbc,
1N/Aand others found on CPAN Search: http://search.cpan.org .
1N/A
1N/A=head2 How do I make a system() exit on control-C?
1N/A
1N/AYou can't. You need to imitate the system() call (see L<perlipc> for
1N/Asample code) and then have a signal handler for the INT signal that
1N/Apasses the signal on to the subprocess. Or you can check for it:
1N/A
1N/A $rc = system($cmd);
1N/A if ($rc & 127) { die "signal death" }
1N/A
1N/A=head2 How do I open a file without blocking?
1N/A
1N/AIf you're lucky enough to be using a system that supports
1N/Anon-blocking reads (most Unixish systems do), you need only to use the
1N/AO_NDELAY or O_NONBLOCK flag from the Fcntl module in conjunction with
1N/Asysopen():
1N/A
1N/A use Fcntl;
1N/A sysopen(FH, "/foo/somefile", O_WRONLY|O_NDELAY|O_CREAT, 0644)
1N/A or die "can't open /foo/somefile: $!":
1N/A
1N/A=head2 How do I install a module from CPAN?
1N/A
1N/AThe easiest way is to have a module also named CPAN do it for you.
1N/AThis module comes with perl version 5.004 and later.
1N/A
1N/A $ perl -MCPAN -e shell
1N/A
1N/A cpan shell -- CPAN exploration and modules installation (v1.59_54)
1N/A ReadLine support enabled
1N/A
1N/A cpan> install Some::Module
1N/A
1N/ATo manually install the CPAN module, or any well-behaved CPAN module
1N/Afor that matter, follow these steps:
1N/A
1N/A=over 4
1N/A
1N/A=item 1
1N/A
1N/AUnpack the source into a temporary area.
1N/A
1N/A=item 2
1N/A
1N/A perl Makefile.PL
1N/A
1N/A=item 3
1N/A
1N/A make
1N/A
1N/A=item 4
1N/A
1N/A make test
1N/A
1N/A=item 5
1N/A
1N/A make install
1N/A
1N/A=back
1N/A
1N/AIf your version of perl is compiled without dynamic loading, then you
1N/Ajust need to replace step 3 (B<make>) with B<make perl> and you will
1N/Aget a new F<perl> binary with your extension linked in.
1N/A
1N/ASee L<ExtUtils::MakeMaker> for more details on building extensions.
1N/ASee also the next question, ``What's the difference between require
1N/Aand use?''.
1N/A
1N/A=head2 What's the difference between require and use?
1N/A
1N/APerl offers several different ways to include code from one file into
1N/Aanother. Here are the deltas between the various inclusion constructs:
1N/A
1N/A 1) do $file is like eval `cat $file`, except the former
1N/A 1.1: searches @INC and updates %INC.
1N/A 1.2: bequeaths an *unrelated* lexical scope on the eval'ed code.
1N/A
1N/A 2) require $file is like do $file, except the former
1N/A 2.1: checks for redundant loading, skipping already loaded files.
1N/A 2.2: raises an exception on failure to find, compile, or execute $file.
1N/A
1N/A 3) require Module is like require "Module.pm", except the former
1N/A 3.1: translates each "::" into your system's directory separator.
1N/A 3.2: primes the parser to disambiguate class Module as an indirect object.
1N/A
1N/A 4) use Module is like require Module, except the former
1N/A 4.1: loads the module at compile time, not run-time.
1N/A 4.2: imports symbols and semantics from that package to the current one.
1N/A
1N/AIn general, you usually want C<use> and a proper Perl module.
1N/A
1N/A=head2 How do I keep my own module/library directory?
1N/A
1N/AWhen you build modules, use the PREFIX and LIB options when generating
1N/AMakefiles:
1N/A
1N/A perl Makefile.PL PREFIX=/mydir/perl LIB=/mydir/perl/lib
1N/A
1N/Athen either set the PERL5LIB environment variable before you run
1N/Ascripts that use the modules/libraries (see L<perlrun>) or say
1N/A
1N/A use lib '/mydir/perl/lib';
1N/A
1N/AThis is almost the same as
1N/A
1N/A BEGIN {
1N/A unshift(@INC, '/mydir/perl/lib');
1N/A }
1N/A
1N/Aexcept that the lib module checks for machine-dependent subdirectories.
1N/ASee Perl's L<lib> for more information.
1N/A
1N/A=head2 How do I add the directory my program lives in to the module/library search path?
1N/A
1N/A use FindBin;
1N/A use lib "$FindBin::Bin";
1N/A use your_own_modules;
1N/A
1N/A=head2 How do I add a directory to my include path (@INC) at runtime?
1N/A
1N/AHere are the suggested ways of modifying your include path:
1N/A
1N/A the PERLLIB environment variable
1N/A the PERL5LIB environment variable
1N/A the perl -Idir command line flag
1N/A the use lib pragma, as in
1N/A use lib "$ENV{HOME}/myown_perllib";
1N/A
1N/AThe latter is particularly useful because it knows about machine
1N/Adependent architectures. The lib.pm pragmatic module was first
1N/Aincluded with the 5.002 release of Perl.
1N/A
1N/A=head2 What is socket.ph and where do I get it?
1N/A
1N/AIt's a perl4-style file defining values for system networking
1N/Aconstants. Sometimes it is built using h2ph when Perl is installed,
1N/Abut other times it is not. Modern programs C<use Socket;> instead.
1N/A
1N/A=head1 AUTHOR AND COPYRIGHT
1N/A
1N/ACopyright (c) 1997-2003 Tom Christiansen and Nathan Torkington.
1N/AAll rights reserved.
1N/A
1N/AThis documentation is free; you can redistribute it and/or modify it
1N/Aunder the same terms as Perl itself.
1N/A
1N/AIrrespective of its distribution, all code examples in this file
1N/Aare hereby placed into the public domain. You are permitted and
1N/Aencouraged to use this code in your own programs for fun
1N/Aor for profit as you see fit. A simple comment in the code giving
1N/Acredit would be courteous but is not required.