Provided by: manpages-zh_1.5-1_all bug

NAME

       perlfaq8 - 系統交互 (2003/01/26 17:44:04 )

DESCRIPTIONyz
       Perl FAQ 的這一節覆蓋了與系統交互有關的問題。主題包括進程間通信
       (IPC),使用者界控惆
       (鍵盤,螢幕和指點設備),以及其他與數據操作不相關的事項

       閱讀你系統中的 perl 自帶的 FAQ 和文件 (例如,perlvms,perlplan9...)。它-
       抪|包含有關你的 perl 版本的更詳細的信息。

      pXbB@~tH

       exec()^?

       因為這正是它所做的:它用另一茪ㄕP的程式來取代你當時所執行的。如果你的程
       式需n繼續跑下去(這可能正是你問此問題的鴞]吧?),改用 system() 。

      pLH

       連接/控制 鍵盤、螢幕和指標裝置(「滑鼠」)的方法因作業系統的不同而有不
       同;不妨試試下列模組:

       Keyboard
               Term::Cap                   標準內建模組
               Term::ReadKey               CPAN
               Term::ReadLine::Gnu         CPAN
               Term::ReadLine::Perl        CPAN
               Term::Screen                CPAN

       Screen
               Term::Cap                   標準內建模組
               Curses                      CPAN
               Term::ANSIColor             CPAN

       Mouse
               Tk                          CPAN

       Some of these specific cases are shown below.

       How do I print something out in color?

       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:

           use Term::ANSIColor;
           print color("red"), "Stop!\n", color("reset");
           print color("green"), "Go!\n", color("reset");

       Or like this:

           use Term::ANSIColor qw(:constants);
           print RED, "Stop!\n", RESET;
           print GREEN, "Go!\n", RESET;

       How do I read just one key without waiting for a return key?

       Controlling input buffering is a remarkably system-dependent matter.
       On many systems, you can just use the stty command as shown in "getc"
       in perlfunc, but as you see, that's already getting you into
       portability snags.

           open(TTY, "+</dev/tty") or die "no tty: $!";
           system "stty  cbreak </dev/tty >/dev/tty 2>&1";
           $key = getc(TTY);           # perhaps this works
           # OR ELSE
           sysread(TTY, $key, 1);      # probably this does
           system "stty -cbreak </dev/tty >/dev/tty 2>&1";

       The Term::ReadKey module from CPAN offers an easy-to-use interface that
       should be more efficient than shelling out to stty for each key.  It
       even includes limited support for Windows.

           use Term::ReadKey;
           ReadMode('cbreak');
           $key = ReadKey(0);
           ReadMode('normal');

       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 (assuming
       your system supports POSIX).

           use HotKey;
           $key = readkey();

       And here's the HotKey module, which hides the somewhat mystifying calls
       to manipulate the POSIX termios structures.

           # HotKey.pm
           package HotKey;

           @ISA = qw(Exporter);
           @EXPORT = qw(cbreak cooked readkey);

           use strict;
           use POSIX qw(:termios_h);
           my ($term, $oterm, $echo, $noecho, $fd_stdin);

           $fd_stdin = fileno(STDIN);
           $term     = POSIX::Termios->new();
           $term->getattr($fd_stdin);
           $oterm     = $term->getlflag();

           $echo     = ECHO | ECHOK | ICANON;
           $noecho   = $oterm & ~$echo;

           sub cbreak {
               $term->setlflag($noecho);  # ok, so i don't want echo either
               $term->setcc(VTIME, 1);
               $term->setattr($fd_stdin, TCSANOW);
           }

           sub cooked {
               $term->setlflag($oterm);
               $term->setcc(VTIME, 0);
               $term->setattr($fd_stdin, TCSANOW);
           }

           sub readkey {
               my $key = '';
               cbreak();
               sysread(STDIN, $key, 1);
               cooked();
               return $key;
           }

           END { cooked() }

           1;

       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 not to block:

           use Term::ReadKey;

           ReadMode('cbreak');

           if (defined ($char = ReadKey(-1)) ) {
               # input was waiting and it was $char
           } else {
               # no input was waiting
           }

           ReadMode('normal');                  # restore normal tty settings

       How do I clear the screen?

       If you only have do so infrequently, use "system":

           system("clear");

       If you have to do this a lot, save the clear string so you can print it
       100 times without calling a program 100 times:

           $clear_string = `clear`;
           print $clear_string;

       If you're planning on doing other screen manipulations, like cursor
       positions, etc, you might wish to use Term::Cap module:

           use Term::Cap;
           $terminal = Term::Cap->Tgetent( {OSPEED => 9600} );
           $clear_string = $terminal->Tputs('cl');

       How do I get the screen size?

       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 "ioctl", but not as illustrative:

           require 'sys/ioctl.ph';
           die "no TIOCGWINSZ " unless defined &TIOCGWINSZ;
           open(TTY, "+</dev/tty")                     or die "No tty: $!";
           unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) {
               die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
           }
           ($row, $col, $xpixel, $ypixel) = unpack('S4', $winsize);
           print "(row,col) = ($row,$col)";
           print "  (xpixel,ypixel) = ($xpixel,$ypixel)" if $xpixel || $ypixel;
           print "\n";

      pVKXH

       (這荌暋D跟全球資訊網一點關系也沒有。如果你n找的是跟 WWW 有關的,那就
       看另一份常見問題集吧。)

       在 perlfunc 中的 "crypt" 裏惘勝範例。漸,將你的終端機設為「無回應」"no
       echo" 模式,然後就用弗`的方法將密碼讀入。你可以用老式的 ioctl() 函數、
       POSIX 終端機控制函數(參看 POSIX ,和駱駝書第七章),或是呼叫 stty
       程式,這些方法的可攜性/移植性程度都不一樣。

       你也可以在大部份系統上使用 CPAN 裏的 Term::ReadKey 模組,這-
       蚍珩楖易使用而且理論上也較據可攜性/移植性。

           use Term::ReadKey;

           ReadMode('noecho');
           $password = ReadLine(0);

      pgfH

       這端看你在什麼作業系統上執行你的程式。以 Unix 來說,序列埠可以透過 /dev
       目錄下的檔案來擷取;
       而在其他系統上,設備的名稱無疑地會不一樣。以下是一些在設備互動時可能遭遇的共同問題:

       lockfiles
           你的系統可能會使用鎖檔來控制多-
           宣盲g的情況。確定你用的是正確的協定。因為當多茧{式同時對一-
           虒佶m做讀取時可能會發生意想不到的情況。

       open mode
           如果你打算對一虒佶m同時做讀與寫的動作,你得將它開到更新的模式( 在
           perlfunc 中的 open
           裏有更詳細的解說)。如果你不希望冒著阻擋其他程式讀取 這虒佶m的-
           滅I,那就得用 sysopen() 和 Fcntl 模組(標準 perl 的一部分)內 的
           "O_RDWR|O_NDELAY|O_NOCTTY"。在 perlfunc 中的 sysopen 裏有對此方法更
           詳盡的解說。

       end of line
           有些裝置會等著在每行結尾處看到一 "\r",而非 "\n"。在某些孕x上的
           perl, "\r"和 "\n" 與它怚常(在 Unix 上)所指的 ASCII  "\015" 和
           "\012" 有 所不同。你也許得直接給定數A例如用八進位
           ("\015")、十六進位 ("0x0D"), 或指定控制字元 ("\cM")。

               print DEV "atv1\012";       # wrong, for some devices
               print DEV "atv1\015";       # right, for some devices

           儘管對普通的文字檔案,一 "\n"
           便可解決斷行的問題,但目前在不同作業系統 間(Unix、DOS/Win 和
           Macintosh),對於斷行記號仍無統一標準,而只有用 "\015\012" 來當成
           每行的結尾,然後再視需n去掉輸出中不想n的部份。這 荌答k尤其常用於
           socket輸出/輸入 與自動刷新 (autoflushing),也是接下來
           n討論的主題。

       flushing output
           如果你希望 print() 的時唻C茼r元都-
           n送到你指定的裝置去,那你應自動刷新檔案句柄。可以使用 select() 和
           $| 變量控制自動刷新,參見 perlvar 中的 "$|" 和 perlfunc 中的
           "select",或 perlfaq5, ``How do I flush/unbuffer an output
           filehandle?  Why must I do this?''):

               $oldh = select(DEV);
               $| = 1;
               select($oldh);

           你也可能看到不使用額外的暫存變數的寫法,例如:

               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:

               use IO::Handle;
               DEV->autoflush(1);

           As mentioned in the previous item, this still doesn't work when
           using socket I/O between Unix and Macintosh.  You'll need to hard
           code your line terminators, in that case.

       non-blocking input
           如果你正在做一茠塞的 read() 或 sysread() 動作,則你需n安排一蚞x
           鈴把手或提供一蚢O時設定(參看 alarm)。如果你是用非阻擋式的
           開檔,那麼就n配合非阻擋性的讀取,也就是說得用到4 荌捊 select()
           來確 定此裝置的 輸出/入 是否已準備好了(參考 perlfunc 中的 select
           )。

       While trying to read from his caller-id box, the notorious Jamie
       Zawinski <jwz@netscape.com>, after much gnashing of teeth and fighting
       with sysread, sysopen, POSIX's tcgetattr business, and various other
       functions that go bump in the night, finally came up with this:

           sub open_modem {
               use IPC::Open2;
               my $stty = `/bin/stty -g`;
               open2( \*MODEM_IN, \*MODEM_OUT, "cu -l$modem_device -s2400 2>&1");
               # starting cu hoses /dev/tty's stty settings, even when it has
               # been opened on a pipe...
               system("/bin/stty $stty");
               $_ = <MODEM_IN>;
               chomp;
               if ( !m/^Connected/ ) {
                   print STDERR "$0: cu printed `$_' instead of `Connected'\n";
               }
           }

      pX[KfOH

       花大把大把的錢去買破解專用的硬體,這會讓你成為焦點話題。

       說正經的,如果是碰到 Unix 密碼檔的話就不行 - Unix
       密碼系統用的是單向的加 密函數。像 Crack
       之類的程式可以暴力地(並聰明地)試著猜出密碼,但無法
       (也不能)保証速戰速決。

       如果你耽心的是使用者選取不良的密碼,你應該在使用者換密碼時主動審核(例如說-
       蚹 passwd(1) 程式加入這茈\能)。

      pbIwait() for your
           first child, and the init daemon will wait() for your grandchild
           once it exits.

                   unless ($pid = fork) {
                           unless (fork) {
                       exec "what you really wanna do";
                       die "exec failed!";
                           }
                   exit 0;
                   }
               waitpid($pid,0);

           在 Signals 有範例程式教你怎麼做。用 system("prog &") 的 話不會有僵
           程式的問題。

      pIr/Unixtp shadowH

       如果你的 perl 安裝正確的話,在 perlfunc 裏描z的 getpw*()
       函數應該就能夠讀取隱式密碼檔了(只有讀取權)。n更動該檔案內容,做一-
       虓s的密碼檔(這蚗仵蛌漁璁’]系統而異,請看 passwd(5) )然後用
       pwd_mkdb(8)(參考 pwd_mkdb(5))來安裝新的密碼檔。

      p]mMH

       假設你有足夠的權,你應該可以用 date(1) 程式來設定系統的時間與日期。
       (但沒有針對荍O程式蚹黈伅﹞暾薊漱隤k)這機制在 Unix、MS-DOS、Windows 和
       NT 下都能用;VMS 下則n用 set time 。

       然而,如果你只是n更動你的時區,只消設定一蚗藿疻僂Y可:

           $ENV{TZ} = "MST7MDT";                  # unixish
           $ENV{'SYS$TIMEZONE_DIFFERENTIAL'}="-5" # vms
           system "trn comp.lang.perl.misc";

      p sleep() alarm()@?

       如果你n比 sleep() 所提供的最小單位一秒更精細的話,最簡單的方法就是用
       select 裏掉g的 select() 函數。試一試 Time::HiRes 和 BSD::Itimer 模塊
       (可以從 CPAN 下載,從 Perl 5.8 開始 Time::HiRes 成為標準發行的一部分).

      p@H

       一般來說,你可能做不到。 Time::HiRes 模組(CPAN 有,從 Perl 5.8
       開始成為標準發行的一部分)在某些系統上能達到此 功能。

       總之,你可能做不到。但是如果你的 Perl 支援 syscall() 函數並支援類似
       gettimeofday(2) 的系統呼叫,你也許可以這麼做:

           require 'sys/syscall.ph';

           $TIMEVAL_T = "LL";

           $done = $start = pack($TIMEVAL_T, ());

           syscall(&SYS_gettimeofday, $start, 0) != -1
                      or die "gettimeofday: $!";

              ##########################
              # DO YOUR OPERATION HERE #
              ##########################

           syscall( &SYS_gettimeofday, $done, 0) != -1
                  or die "gettimeofday: $!";

           @start = unpack($TIMEVAL_T, $start);
           @done  = unpack($TIMEVAL_T, $done);

           # fix microseconds
           for ($done[1], $start[1]) { $_ /= 1_000_000 }

           $delta_time = sprintf "%.4f", ($done[0]  + $done[1]  )
                                                   -
                                        ($start[0] + $start[1] );

      p atexit()setjmp()/longjmp()socketsSystem V
       (Solaris)PerlCioctl()syscall()cpp(1)指令轉換成內含副程式定義的檔案,像
       &SYS_getitimer,你可
       以把它當做函數的參數。這樣做並不怎麼完美,但通常可達成任務。簡單的像
       errno.h 、syscall.h 和socket.h 這些檔案都沒問題,但像 ioctl.h
       這種較難的檔案總是需n人工編輯。以下是安裝 *.ph 檔案的步驟:

           1.  成為超級使用者
           2.  cd /usr/include
           3.  h2ph *.h */*.h

       如果你的系統支援動態載入,那麼為了可移植性、而且合理的做法是使用
       h2xs(也 是 perl的標準配備)。這茪u具將 C 標頭檔案轉換成 Perl 的l伸檔案
       (extensions)。 h2xs 的入門n看 perlxstut 。

       如果你的系統不支援動態載入,你可能仍應使用 h2xs。參看 perlxstut 和
       MakeMaker (簡單來說,就是用 make perl 、而非 make 來
       建一份使用新的靜態連結的 perl)。

       setuid perl(pipe)system()STDERRsh(1)) 姥阞獄y法而非
       csh(1)的!至於為何 Perl 的 system()、反向引號和開管道都用 Bourne
       shell語法的鴞],可在下址找到:"Far More Than You Ever Wanted To Know",
       http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz .  n同時捕捉一茤R令的
       STDERR 和 STDOUT:

           $output = `cmd 2>&1`;                       # either with backticks
           $pid = open(PH, "cmd 2>&1 |");              # or with an open pipe
           while (<PH>) { }                            #    plus a read

       To capture a command's STDOUT but discard its STDERR:

           $output = `cmd 2>/dev/null`;                # either with backticks
           $pid = open(PH, "cmd 2>/dev/null |");       # or with an open pipe
           while (<PH>) { }                            #    plus a read

       To capture a command's STDERR but discard its STDOUT:

           $output = `cmd 2>&1 1>/dev/null`;           # either with backticks
           $pid = open(PH, "cmd 2>&1 1>/dev/null |");  # or with an open pipe
           while (<PH>) { }                            #    plus a read

       To exchange a command's STDOUT and STDERR in order to capture the
       STDERR but leave its STDOUT to come out our old STDERR:

           $output = `cmd 3>&1 1>&2 2>&3 3>&-`;        # either with backticks
           $pid = open(PH, "cmd 3>&1 1>&2 2>&3 3>&-|");# or with an open pipe
           while (<PH>) { }                            #    plus a read

       To read both a command's STDOUT and its STDERR separately, it's easiest
       and safest to redirect them separately to files, and then read from
       those files when the program is done:

           system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");

       Ordering is important in all these examples.  That's because the shell
       processes file descriptor redirections in strictly left to right order.

           system("prog args 1>tmpfile 2>&1");
           system("prog args 2>&1 1>tmpfile");

       The first command sends both standard out and standard error to the
       temporary file.  The second command sends only the old standard output
       there, and the old standard error shows up on the old standard out.

      D} open()open() contains shell metacharacters,
       perl fork()s, then exec()s 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 "How can I capture STDERR from an external command?"
       elsewhere in this document, or use the IPC::Open3 module.

       If there are no shell metacharacters in the argument of open(), Perl
       runs the command directly, without using the shell, and can correctly
       report whether the command started.

      b^WUVH

       嚴格說起來,沒啥不對。但從程式寫作嚴謹與否來說,這樣無法寫出較易維護的程式碼。Perl
       有多種方法可以運行外部命令。反引號只是其中一-
       荂F它收集命令的輸出,在程式中加以應用。 "system" 函數是另一-
       荂A它不這樣做

       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.  Why
       send a clear message that isn't true?

       再看看下列這一行:

           `cat /etc/termcap`;

       你還沒有指定輸出,所以它會浪費記憶體(就那麼一下子)。另外你也忘了檢查
       $? 看看程式是否正確的執行。即使你寫成

           print `cat /etc/termcap`;

       但在大部份情況下,這本來可以、而且也應該寫成

           system("cat /etc/termcap") == 0
               or die "cat program failed!";

       這樣可快速地得到輸出(一產生出來就會得到,不用等到最後),並且檢查傳回-
       C

       system() 同時具有直接決定是否先做 shell 萬用字元 (wildcard)處理的功能,
       反向引號就不行。

      pgL shellopen()。類似 system()exec()
       的列表形式,不會進行 shell 轉義。

          open( GREP, "-|", 'grep', @opts, $search_string, @filenames );
          chomp(@ok = <GREP>);
          close GREP;

       也可以這樣:

           my @ok = ();
           if (open(GREP, "-|")) {
               while (<GREP>) {
                   chomp;
                   push(@ok, $_);
               }
               close GREP;
           } else {
               exec 'grep', @opts, $search_string, @filenames;
           }

       一如 system(),當你 exec() 一荍C時不會有 shell
       解譯的情況發生。更多示例可以從 perlipc 的 "Safe Pipe Opens" 中找到。

       Note that if you're use Microsoft, no solution to this vexing issue is
       even possible.  Even if Perl were to emulate fork(), you'd still be
       stuck, because Microsoft does not have a argc/argv-style API.

      F EOFUnix^DMS-DOS^ZSTDIN
      FFOH

       因為某些 stdio 的 set error 和 eof 旗標需n清除。你可以用 POSIX 模組裏定
       義的clearerr()。這是在技術上正確的解決之道。還有一些較不保險的方法:

       1   試著保存搜尋指標然後去找它,例如:

               $where = tell(LOG);
               seek(LOG, $where, 0);

       2   如果那樣行不通,試著去 seek() 檔案的另一部份然後再找回來。

       3   如果還是行不通,試著 seek() 檔案另一-
           茯蛢妒漯熙‘驉A讀點東西,再回去找。

       4   如果依然不行,放棄使用 stdio 改用 sysread。

      p shellperlperltelnetftp|H

       試試 Net::FTP、TCP::Client 和 NET::Telnet 模組(CPAN 有)。
       http://www.perl.com/CPAN/scripts/netstuff/telnet.emul.shar 也有助於模擬
       telnet 協定,但是 Net::Telnet 可能較容易使用。

       如果你所n做的只是假裝 telnet 但又不n起始 telnet
       時的溝通程式,那麼以下這蚍郱甄驧{式方式就可以滿足你的需n了:

           use IO::Socket;             # new in 5.004
           $handle = IO::Socket::INET->new('www.perl.com:80')
                   || die "can't connect to port 80 on www.perl.com: $!";
           $handle->autoflush(1);
           if (fork()) {               # XXX: undef means failure
               select($handle);
               print while <STDIN>;    # everything from stdin to socket
           } else {
               print while <$handle>;  # everything from socket to stdout
           }
           close $handle;
           exit;

      pb PerlExpectperlAH像

       漸n注意的是,如果你的目的是為了安全(例如避免人-
       怜蓮搢麇K碼),那你應該姨g你的程式,把南的資訊從參數中-
       蝪ㄐC光是隱藏起來不會讓你的程式變得完全安全。

       如n真的把看得見的指令列改掉,你可以設定 $0 這蚥僂,如同 perlvar
       裏寫的。但這方法並非各種作業系統都適用。像 sendmail之類的I景程式
       (daemons) 就將它怐漯牯A放在那兒:

           $0 = "orcus [accepting connections]";

      b perl script{-
      SXH

       Unix
           嚴格的說起來,這是做不到的-一 script 的執行是從啟動它的 shell
           生出一 茪ㄕP的程式來執行。這-
           茧{式的任何變動不會反映到它的父程式,只會反映到更
           改之後它自己創造出來的子程式。有 shell 魔術可以讓你藉著在 shell 裏
           eval()你 script 的輸出來裝出這種效果,在 comp.unix.questions FAQ
           裏有詳 細內容。

      p@{y`OH

       假設你的系統支援這種功能,那就只n送蚞A當的訊號給此程式(參看
       kill)。通常是先送一 TERM 訊號,等一下下,然後再送 KILL
       訊號去終結它。

      p fork@u@i{H

       如果你所指的是離線的程式(未與 tty 連線者),那下列的程式據說在大部份的
       Unix系統都能用。非 Unix 系統的使用者應該檢查 Your_OS::Process
       模組看看有 沒有其他的解決方案。

       o   打開 /dev/tty 然後對它用 TIOCNOTTY ioctl。請參考 tty(4)
           。更好的辦法,你可以只用 POSIX::setsid() 函數,從而不必擔心進程組。

       o   把目錄換到 /

       o   奎} STDIN、STDOUT 和 STDERR 使它怳ㄦ|與舊的 tty 連接。

       o   用下列方法把程式丟到I景:

               fork && exit;

       The Proc::Daemon module, available from CPAN, provides a function to
       perform these actions for you.

      pDvObaBH

       問得好。有的時 "-t STDIN"N 和 "-t STDOUT" 可以提供線索,有時不行。

           if (-t STDIN && -t STDOUT) {
               print "Now what? ";
           }

       在 POSIX 系統中,你可以用以下方法測試你自己的程式群組與現在控制你終端機
       的是否相同:

           use POSIX qw/getpgrp tcgetpgrp/;
           open(TTY, "/dev/tty") or die $!;
           $tpgrp = tcgetpgrp(fileno(*TTY));
           $pgrp = getpgrp();
           if ($tpgrp == $pgrp) {
               print "foreground\n";
           } else {
               print "background\n";
           }

      pwC]mWH

       如同 Signals 和 Camel 書第六章裏所描z的,用 alarm() 函數,
       或許再配合上一荌T號處理器。你也可以改用 CPAN 裏更具彈性的
       Sys::AlarmCall 模組來做。

       The alarm() function is not implemented on all versions of Windows.
       Check the documentation for your specific version of Perl.

      p]m CPUB?

       使用 CPAN 裏的 BSD::Resource 模組。

      pKb Unixti{H

       使用 Signals 裏悼s reaper 的程式碼,在接到 SIGCHLD 時會呼
       叫wait(),或是用 perlfaq8 中的 "How do I start a process in the
       background?" 裏掉g的雙 fork 技巧。

      p SQLw?

       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 .

      p system()b control-ChX?

       做不到。你需n摹仿 system() 呼叫(參看 perlipc 裏的範例程式),然後設-
       p一荌T號處理器,讓它把 INT 訊號傳給子程式。或者可以檢測它:

           $rc = system($cmd);
           if ($rc & 127) { die "signal death" }

      pLa}@H

       如果你有幸使用到支援無阻塞讀的系統(大部份 Unix 般的系統都有支援),
       你只需n用 Fcntl 模組裏的 O_NDELAY 或 O_NONBLOCK 旗標,配合 sysopen():

           use Fcntl;
           sysopen(FH, "/tmp/somefile", O_WRONLY|O_NDELAY|O_CREAT, 0644)
               or die "can't open /tmp/somefile: $!":

       How do I install a module from CPAN?

       最簡單的方法就是讓 CPAN 這蚍珩桭嬪A代勞。這蚍珩掍]含在 5.004及以後的版
       本中。

           $ perl -MCPAN -e shell

           cpan shell -- CPAN exploration and modules installation (v1.59_54)
           ReadLine support enabled

           cpan> install Some::Module

       如n手動安裝 CPAN 模組,或是任何按規矩發展的 CPAN模組,遵循以下步 驟:

       1   把鴝l碼解壓到臨時目錄

       2
               perl Makefile.PL

       3
               make

       4
               make test

       5
               make install

       如果你用的 perl 版本在編譯時沒有建入動態連結的功能,那你只消把第三步
       (make)換成 make perl 然後你就會得到一虓s的 perl 執行檔,裏頭連
       有你新加入的延伸。

       在 ExtUtils::MakeMaker 裏惘釦韟h關於建構模組的細節,並參考下一-
       荌暋D,require 和 use 的區別是什麼?。

       requireM useOOH

       Perl offers several different ways to include code from one file into
       another.  Here are the deltas between the various inclusion constructs:

           1)  do $file is like eval `cat $file`, except the former
               1.1: searches @INC and updates %INC.
               1.2: bequeaths an *unrelated* lexical scope on the eval'ed code.

           2)  require $file is like do $file, except the former
               2.1: checks for redundant loading, skipping already loaded files.
               2.2: raises an exception on failure to find, compile, or execute $file.

           3)  require Module is like require "Module.pm", except the former
               3.1: translates each "::" into your system's directory separator.
               3.2: primes the parser to disambiguate class Module as an indirect object.

           4)  use Module is like require Module, except the former
               4.1: loads the module at compile time, not run-time.
               4.2: imports symbols and semantics from that package to the current one.

       In general, you usually want "use" and a proper Perl module.

      p]mv//include| (@INC)H

       以下是我怮媊釦饇吨牏J路徑的方法:

           環境變量 PERLLIB
           環境變量 PERL5LIB
           perl -Idir 命令行標誌
           use lib 編用,類似
               use lib "$ENV{HOME}/myown_perllib";

       後者特別有用,因為它知道與機器相關的架構。lib.pm 機制模組是從 5.002
       版開 始包含在 Perl 裏悸滿C

      O socket.ph

AUTHOR AND COPYRIGHT

       Copyright (c) 1997-2003 Tom Christiansen and Nathan Torkington.  All
       rights reserved.

       This documentation is free; you can redistribute it and/or modify it
       under the same terms as Perl itself.

       Irrespective of its distribution, all code examples in this file are
       hereby placed into the public domain.  You are permitted and encouraged
       to use this code in your own programs for fun or for profit as you see
       fit.  A simple comment in the code giving credit would be courteous but
       is not required.

者
      AAuu@室