看板 Perl 關於我們 聯絡資訊
※ 引述《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)
Yaowei:先感謝大家 小弟好好研究一下^^ 03/11 18:14