Re: [問題] 請問使用檔案比對時?
※ 引述《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
討論串 (同標題文章)
Perl 近期熱門文章
PTT數位生活區 即時熱門文章