轉:一個在文字檔案搜尋指定字串的程式

herosoft發表於2009-07-21

用perl實現的.

[@more@]


print "input file:";
$file=;
chomp($file);
open (Hand,$file)||die "can not open file";

print "input the string to search:";
$str=;
chomp($str);

print "the result:n";

$i=0;
while ()
{
$i++;
while (/$str/g)
{
print "line".$i.": ".$_;
}
}
儲存為search.pl
C:>perl search.pl
input file:hello.txt
input the string to search: hello
the result:
line2: this is a hello test.
lien5: helloworld.
這個程式執行特別快.


本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/treeroot/archive/2004/10/09/129199.aspx

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/220284/viewspace-1024365/,如需轉載,請註明出處,否則將追究法律責任。

相關文章