Re: [問題] 一個應該算簡單的問題

看板Perl作者 (連做夢都在微笑)時間17年前 (2007/03/10 01:29), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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

03/10 14:30, , 1F
超級感謝 我改一改之後就可以了^^感恩感恩
03/10 14:30, 1F
文章代碼(AID): #15yPbmx5 (Perl)
文章代碼(AID): #15yPbmx5 (Perl)