看板 Perl 關於我們 聯絡資訊
※ 引述《Yaowei (成就你的大事)》之銘言: : 假設我有一個檔案內容如下: : synaptodendritic B-protein : domains I-protein : Job B-protein : kinases B-protein : 5′ B-protein : stem-loop I-protein : domain I-protein : ---------------------------------------- : 上面都是以\t(tab鍵)作為間隔 : 其判斷規則是B-protein結尾一定是開頭 : 然後若其後有出現I-protein結尾的話則一直取出直到遇到B-protein為止 : 若只有單獨的B-protein結尾而後面沒有I-protein,則只取出B-Protein前那個字即可 : 然後我想取得 synaptodendritic domains,Job,kinases,5′ stem-loop domain : 請問要怎麼寫呢?感謝大家=\ = $out = ""; while (<DATA>) { if (/(.*)\tB-protein/) { print $out.',' if ($out ne ""); $out = $1; } elsif (/(.*)\tI-protein/) { $out .= ' '.$1; } } print $out.$/ if ($out ne ""); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.29.131
Yaowei:超級感謝 我改一改之後就可以了^^感恩感恩 03/10 14:30