Source: 不止一種方法去做一件事
不止一種方法去做一件事(There's more than one way to do it,TMTOWTDI或TIMTOWTDI,發音為「Tim Toady」)是一條Perl俗語。這個語言本身就是用這個「不要教程式設計師如何編程」的主意設計的。這使得很容易可以寫出極度雜亂的程序,但是,根據支持者對這個俗語的理解,這也可以很容易地寫出簡潔的語句。
Continue reading »Source: 不止一種方法去做一件事
不止一種方法去做一件事(There's more than one way to do it,TMTOWTDI或TIMTOWTDI,發音為「Tim Toady」)是一條Perl俗語。這個語言本身就是用這個「不要教程式設計師如何編程」的主意設計的。這使得很容易可以寫出極度雜亂的程序,但是,根據支持者對這個俗語的理解,這也可以很容易地寫出簡潔的語句。
Continue reading »原文(source): IT 台灣郎: 去除文件中的 ^M
perl -p -i -e 's/\r\n$/\n/g' file1.txt
Recipe 6.15. Greedy and Non-Greedy Matches
You have a pattern with a greedy quantifier like *
, +
, ?
, or {}
, and you want to stop it from being greedy.
好文: 一行指令 格式化 印出 設定檔(my.cnf) | Tsung's Blog
一行 Perl 的命令, 格式化印出 my.cnf 檔, 同樣做法, 也可以用在其它 conf file.(ex: php.ini)
Perl 基本格式 (Hello、JSON 寫法) | Tsung's Blog
DK 寫 Perl 的標準寫法, 主程式都寫於 main() 中, 整個程式看起來會比較容易懂~ 🙂
註: 此為參考寫法, 並非絕對~
Perl trim function to strip whitespace from a string
Perl does not have a built-in trim function. Use the subroutine below to trim whitespace (spaces and tabs) from the beginning and end of a string in Perl. This function is directly based on the Perl FAQ entry, How do I strip blank space from the beginning/end of a string?. The ltrim
and rtrim
functions can trim leading or trailing whitespace.
Continue reading »
Jeremy Mates’s Blog: Delete Element from Array
A common Perl programming question is “how can I remove one or more elements from an array?” Some approaches to this problem have unexpected side-effects best revealed by Data::Dumper and minimal test data.