看板 Perl 關於我們 聯絡資訊
Code 1檢查a.txt每一行如果b.txt有這行,flag++ -------------------------------------------------------- open(FILE,"a.txt");@A=<FILE>;close(FILE); open(FILE,"b.txt");@B=<FILE>;close(FILE); foreach $line (@A) { next if ($line eq "\n"); $flag ++ if ( grep(/$line/,@B) ); } print $flag; ------------------------------------------------------- Code 2 a.txt每一行將對應的hash++,檢查b.txt每一行對應的 hash如果有值,則flag++ -------------------------------------------------------- open(FILE,"a.txt");@A=<FILE>;close(FILE); open(FILE,"b.txt");@B=<FILE>;close(FILE); ($_ eq "\n")?1:$HASH{$_}++ foreach (@A); ($HASH{$_})?$flag++:1 foreach(@B); print $flag; ------------------------------------------------------- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.74.242.13
imce:慢了一步,有錯請指正謝謝 05/06 00:10
※ 編輯: imce 來自: 211.74.242.13 (05/06 00:16)
abliou:感謝喔.. 05/06 02:36