Re: [問題] 請問使用檔案比對時?

看板Perl作者 (零式札克)時間18年前 (2007/03/11 15:02), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串6/6 (看更多)
※ 引述《david220 (連做夢都在微笑)》之銘言: : open(IF, "patterns.txt") or die "cannot open: $!"; : chomp(@patterns = <IF>); : close IF; : open(IF, "data.txt") or die "cannot open: $!"; : map {$line = $_; print $line if(grep {$line =~ s/$_/<NP>/} @patterns);} <IF>; : close IF; ... 超懶人作法 全部丟給 regexp >w<; open( F2, "<./2" ); # read patterns $pat = '('. join( '|', map{ chomp; $_; }<F2> ). ')'; close( F2 ); open( F1, "<./1" ); # compare and replace grep{ print( $`, '<NP>', $' ) if( /$pat/ ); }<F1>; close( F1 ); 但是這樣檔案大起來效率一定超爛 XD -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.216.174.26 ※ 編輯: reizarc 來自: 61.216.174.26 (03/11 15:04)

03/11 18:14, , 1F
先感謝大家 小弟好好研究一下^^
03/11 18:14, 1F
文章代碼(AID): #15ywbwgG (Perl)
文章代碼(AID): #15ywbwgG (Perl)