perlfaq - perl常問問題集
目錄
perlfaq
篇名
概述
如何取得這份文件?
如何替這份文件盡點力?
如果把寫 Perl程式時所遇到的問題寄去問作者會有什麼後果?
功勞
作者及版權事宜
非商業性之翻印及轉載
商業性之翻印及轉載
聲明
原文版更動記錄
perlfaq1
篇名
概述
Perl是什麼?
誰對 perl提供支援?由誰負責發展?它為什麼是免費的?
我該用哪一個版本的 Perl?
perl4和 perl5各代表什麼?
Perl的發展已穩定了嗎?
Perl難學嗎?
Perl和其他的程式語言比起來如何?例如 Java, Python, REXX, Scheme,或 Tcl?
我可以用 Perl來做【某種差事】嗎?
哪些場合下不適合用 Perl?
「perl」和「Perl」有什麼不同?
Perl程式應算是 program還是 script?
JAPH是什麼?
到哪兒可拿到 Larry Wall的智慧諷語 (witticisms)?
我要如何取信、說服我的系統管理者/上司/屬下使用第 5/5.004版的 Perl,而不去用其他的語言?
作者及版權事宜
perlfaq2
篇名
概述
哪些平台上有 Perl?要到哪裡去找?
要如合取得以執行檔形式發行的 Perl?
我的系統裡沒有 C編譯器。要如何編譯 perl?
我直接將 Perl的執行檔從一台機器上複製到另一台機器上,但是程式跑不起來。
我抓回了原始碼,試著編譯 perl,但是 gdbm/dynamic loading/malloc/linking/...部分失敗。要如何將它搞定?
Perl有哪些模組和延伸? CPAN是什麼? CPAN/src/...又代表什麼?
是不是有一個經 ISO【國際標準局】或 ANSI【美國國家標準局】認可的 Perl版本?
Perl的相關資料要上哪兒找?
USENET上有哪些專門討論 Perl的新聞討論群?問題該投到哪裡?
如果我想投程式原始碼,該投到哪個板子上?
Perl書籍
和 Perl有關的雜誌
網路上的 Perl:透過 FTP和 WWW
有哪些討論 Perl的郵遞論壇(mailing lists)?
存有 comp.lang.perl.misc posts的檔案庫
Perl訓練課程
如何購買商業版本的 Perl?
如果發現 bugs要向何處報告?
什麼是 perl.com、 perl.org,和 Perl Institute?
如何學著用 Perl來寫物件導向程式?
作者及版權事宜
perlfaq3
篇名
概述
我如何作 (任何事)?
如何以互動的方式使用 Perl?
有 Perl shell嗎?
如何替我的 Perl程式除蟲?
如何檢測 (profile)我的 perl程式?
如何替我的 Perl程式作交叉參考 (cross-reference)?
有 Perl專用的美化列印程式 (pretty-printer)嗎?
有 Perl的 ctags嗎?
哪裡有 vi用的 Perl巨集?
給 emacs用的 perl模式又要去哪抓呢?
如何在 Perl裡使用 curses?
X或 Tk如何與 Perl配合呢?
如何不靠 CGI或 Tk之助作出簡單的目錄(選單)?
我可以動態地將 C常式載入 Perl嗎?
什麼是 undump?
如何讓我的 Perl程式跑得更快些?
如何讓我的 Perl程式吃少一點的記憶體?
把指標傳回到區域資料是不安全的做法嗎?
我如何釋放一個陣列或雜湊陣列以縮小我的程式尺寸?
如何讓我的 CGI腳本 (script)執行起來更有效率?
如何隱藏 Perl程式的原始碼?
如何把我的 Perl程式碼編譯成 byte code或 C?
如何才能讓 '#!perl'在 [MS-DOS,NT,...]下作用?
我能利用命令列寫出有用的程式嗎?
為何一行的 perl程式無法在我的 DOS/Mac/VMS系統上運作?
我得去哪裡學 Perl的 CGI或是 Web程式設計呢?
在哪可以學到用 Perl作物件導向程式設計?
哪裡可以學到將 C與 Perl相連結? [h2xs, xsubpp]
我已經讀了 perlembed, perlguts,等等,但我仍然無法將 perl嵌入我的
當我試著執行我的程式時,我收到某項訊息。它代表什麼意思?
什麼是 MakeMaker?
作者與版權事宜
perlfaq4
NAME
DESCRIPTION
Data: Numbers
Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?
Why isn't my octal data interpreted correctly?
Does perl have a round function? What about ceil() and floor()?
How do I convert bits into ints?
How do I multiply matrices?
How do I perform an operation on a series of integers?
How can I output Roman numerals?
Why aren't my random numbers random?
Data: Dates
How do I find the week-of-the-year/day-of-the-year?
How can I compare two date strings?
How can I take a string and turn it into epoch seconds?
How can I find the Julian Day?
Does Perl have a year 2000 problem?
Data: Strings
How do I validate input?
How do I unescape a string?
How do I remove consecutive pairs of characters?
How do I expand function calls in a string?
How do I find matching/nesting anything?
How do I reverse a string?
How do I expand tabs in a string?
How do I reformat a paragraph?
How can I access/change the first N letters of a string?
How do I change the Nth occurrence of something?
How can I count the number of occurrences of a substring within a string?
How do I capitalize all the words on one line?
How can I split a [character] delimited string except when inside [character]? (Comma-separated files)
How do I strip blank space from the beginning/end of a string?
How do I extract selected columns from a string?
How do I find the soundex value of a string?
How can I expand variables in text strings?
What's wrong with always quoting "$vars"?
Why don't my <
Data: Arrays
What is the difference between $array[1] and @array[1]?
How can I extract just the unique elements of an array?
How can I tell whether an array contains a certain element?
How do I compute the difference of two arrays? How do I compute the intersection of two arrays?
How do I find the first array element for which a condition is true?
How do I handle linked lists?
How do I handle circular lists?
How do I shuffle an array randomly?
How do I process/modify each element of an array?
How do I select a random element from an array?
How do I permute N elements of a list?
How do I sort an array by (anything)?
How do I manipulate arrays of bits?
Why does defined() return true on empty arrays and hashes?
Data: Hashes (Associative Arrays)
How do I process an entire hash?
What happens if I add or remove keys from a hash while iterating over it?
How do I look up a hash element by value?
How can I know how many entries are in a hash?
How do I sort a hash (optionally by value instead of key)?
How can I always keep my hash sorted?
What's the difference between "delete" and "undef" with hashes?
Why don't my tied hashes make the defined/exists distinction?
How do I reset an each() operation part-way through?
How can I get the unique keys from two hashes?
How can I store a multidimensional array in a DBM file?
How can I make my hash remember the order I put elements into it?
Why does passing a subroutine an undefined element in a hash create it?
How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
How can I use a reference as a hash key?
Data: Misc
How do I handle binary data correctly?
How do I determine whether a scalar is a number/whole/integer/float?
How do I keep persistent data across program calls?
How do I print out or copy a recursive data structure?
How do I define methods for every class/object?
How do I verify a credit card checksum?
AUTHOR AND COPYRIGHT
perlfaq5
NAME
DESCRIPTION
How do I flush/unbuffer a filehandle? Why must I do this?
How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?
How do I count the number of lines in a file?
How do I make a temporary file name?
How can I manipulate fixed-record-length files?
How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?
How can I set up a footer format to be used with write()?
How can I write() into a string?
How can I output my numbers with commas added?
How can I translate tildes (~) in a filename?
How come when I open the file read-write it wipes it out?
Why do I sometimes get an "Argument list too long" when I use <*>?
Is there a leak/bug in glob()?
How can I open a file with a leading ">" or trailing blanks?
How can I reliably rename a file?
How can I lock a file?
What can't I just open(FH, ">file.lock")?
I still don't get locking. I just want to increment the number in the file. How can I do this?
How do I randomly update a binary file?
How do I get a file's timestamp in perl?
How do I set a file's timestamp in perl?
How do I print to more than one file at once?
How can I read in a file by paragraphs?
How can I read a single character from a file? From the keyboard?
How can I tell if there's a character waiting on a filehandle?
How do I open a file without blocking?
How do I create a file only if it doesn't exist?
How do I do a
tail -f
in perl?
How do I dup() a filehandle in Perl?
How do I close a file descriptor by number?
Why can't I use "C:\temp\foo" in DOS paths? What doesn't `C:\temp\foo.exe` work?
Why doesn't glob("*.*") get all the files?
Why does Perl let me delete read-only files? Why does
-i
clobber protected files? Isn't this a bug in Perl?
How do I select a random line from a file?
AUTHOR AND COPYRIGHT
perlfaq6
篇名
概述
我該如何使用正規表示式才不至於寫出不合語法且難以維護的程式碼?
我無法對應到超過一行的內容,哪裡出了問題?
我如何取出位於不同行的兩個模式間之內容?
我把一個正規表示式放入 $/但卻沒有用。錯在哪裡?
如何在 LHS端【譯註:式子中運算元左端部份】作不區別大小寫式的替換,但在 RHS端【右端】保留大小寫區別?
如何使
\w
對應到附重音記號 (accented)的字元?
如何作一個適合不同 locale【譯註:國家、地區在文字編碼上各自的慣例】的
/[a-zA-Z]/
對應?
在一個正規表示式裡如何引入 (quote)變數?
/o
到底是幹麼用的?
如何使用正規表示式將檔案中 C語言樣式的註解刪掉?
我能用 Perl的正規表示式去對應成對的符號嗎?
有人說正規表示式很貪婪,那是什麼意思?該如何避免它所帶來的問題?
如何處理每一行的每個字?
我如何印出文字出現頻率或行出現頻率的綱要?
如何能作近似對應?
我如何有效率地一次對應多個正規表示式?
為何我用
\b
作字界搜尋時會失敗呢?
為什麼每當我用 $&, $`,或 $'時程式的速度就慢下來了呢?
正規表示式中的
\G
能給我什麼好處?
Perl正規表示引擎是 DFAs或 NFAs?它們是 POSIX相容的嗎?
在無遞回的場合下用 grep或 map有什麼不對?
如何對應多位元組字母所構成的字串?
作者與版權事宜
perlfaq7
篇名
概述
我能拿到 Perl的 BNF/yacc/RE嗎?
$@%*這些符號是什麼意思?我怎麼知道何時該使用他們呢?
字串加引號或使用分號及逗號是否絕對必要/還是完全沒必要?
我如何跳過一些傳回值?
我如何暫時濾掉警告訊息?
什麼是一個擴充 (extension)?
為何 Perl運算子的優先順序和 C的不一樣?
我如何宣告/生成一個資料結構 (structure)?
我如何創造出一個模組 (module)?
我如何創造一個類別 (class)?
我如何辨別一個變數是否被污染了(tainted)?
閉包 (closure)是啥?
何謂變數自殺而我又該如何防止它?
我如何傳遞/傳回一個 {函數,檔案把手,陣列,雜湊陣列,方法,和正規表現式}?
我如何生成一個靜態變數?
動態與文字式(靜態)範圍界定 (scoping)有何不同? Local()和 my()呢?
當同一個範圍中有一個文字式變數時,我該如何去擷取同名的動態變數?
所謂深連結與淺連結 (deep and shallow binding)間有何不同呢?
為何 "local($foo) =
;"無法正確地作用?
我如何重新定義一個內建函數、運算子或是方法?
用 &foo和 foo()的方式來呼叫一個函數有什麼不同?
我如何作一個 switch或 case敘述?
我如何抓到呼叫未定義變數/函數/方法的事件?
為什麼我的程式會找不到放在同一檔案中的方法 (method)呢?
我如何找出目前所在的 package為何?
我如何將一大塊 perl程式碼變成註解?
作者與版權事宜
perlfaq8
篇名
概述
如何得知使用者正在哪個作業系統下執行我的 perl程式?
為什麼 exec()不會傳值回來?
如何對鍵盤/螢幕/滑鼠做些花樣?
如何向使用者詢問密碼?
如何對序列埠做讀寫動作?
如何逆解加密後的密碼檔案?
如何啟動一個背景執行的程序?
如何捕捉控制字元/訊號?
如何更動 Unix系統上隱式密碼檔 (shadow password)的內容?
如何設定時間和日期?
如何能夠針對小於一秒的時間做 sleep()或 alarm()的動作呢?
如何測量小於一秒的時間?
如何做 atexit()或 setjmp()/longjmp()的動作?(例外處理)
為何我的 sockets程式在 System V (Solaris)系統下不能用?「不支援本協定」這個錯誤訊息又是什麼意思?
如何從 Perl裡呼叫系統中獨特的 C函數?
在哪裡可以找引入檔來做 ioctl()或 syscall()?
為何 setuid perl程式會抱怨關於系統核心的問題?
如何打開對某程式既輸入又輸出的管道 (pipe)?
為何用 system()卻得不到一個指令的輸出呢?
如何補捉外部指令的 STDERR?
為何當管道開啟失敗時 open()不會傳回錯誤訊息?
在輸出值是空的情境裡使用反向引號有何不對?
如何不經過 shell處理來呼叫反向引號?
為何給了 EOF(Unix上是 ^D,MS-DOS上是 ^Z)後我的程式就不能從 STDIN讀取東西了呢?
如何把 shell程式轉成 perl?
perl能處理 telnet或 ftp這種雙向互動嗎?
如何在 Perl裡達到 Expect的功能?
有沒有可能將 perl的指令列隱藏起來,以躲避像 "ps"之類的程式?
我在 perl script裡 {更動目錄,更改我的使用環境}。為何這些改變在程式執行完後就消失了呢?如何讓我做的修改顯露出來?
如何關閉一個程序的檔案把手而不用等它完成呢?
如何 fork出一個背景執行 (daemon)程序?
如何使我的程式和 sh及 csh一起執行?
如何得知我是否正在互動模式下執行?
如何讓一個緩慢的事件過時?
如何設定 CPU使用限制?
在 Unix系統上如何避免產生僵屍程序 (zombies)?
如何使用一個 SQL資料庫?
如何讓 system()在收到 control-C後就離開?
如何開啟一個檔案但不阻擋其他程序的閱讀?
如何安裝一個 CPAN模組?
如何保有一份自己的模組/程式庫目錄?
如何把我的程式所在位置加入模組/程式庫搜尋路徑?
如何在執行時添加目錄到自己的引入路徑中?
如何從終端機一次抓進一個按鍵?如果用 POSIX模組時又該怎麼做?
作者、譯者與版權
perlfaq9
篇名
概述
我的 CGI script可在指令列下執行但無法從瀏覽器執行。您能不能幫我修修看?
如何去除文章中的 HTML標籤?
如何萃取 URLs?
如何從 user端上傳資料?如何在另一台機器上開一個檔案?
如何在 HTML中做 pop-up menu(跳出式選單)?
如何抓 HTML檔案?
如何解開或產生 Web上那些冠 %的碼?
如何【將 requests】轉向到另一頁去?
如何替網頁加上密碼?
要怎麼用 Perl來編輯 .htpasswd和 .htgroup這兩個檔案?
如何防範使用者藉由填我的 CGI表格來做壞事?
如何解讀、萃取 email標頭資料?
如何解譯 CGI表格?
如何驗證 email位址?
如何解 MIME/BASE64字串?
如何根據使用者帳戶名稱自動合成 email位址?
我的程式如何送/讀 email?
如何找出我的主機名/網域名/IP位址?
如何抓新聞討論群的文章或群組名錄?
如何抓/丟 FTP檔案?
如何用 Perl做 RPC?
作者及版權事宜