看板 Perl 關於我們 聯絡資訊
大家好 小弟最近在練習ㄧ個題目 將.lib裡面的cell 取出來 並且依照cell名稱另存新檔 目前,已經可以成功的取出來 但是名稱上面依舊有著(),我只想保留裡面的名稱 例如 cell (FADDS1), 我只想要取出FADDS1而不要有() 但是每個名稱不見得ㄧ樣長度 不知道各位大大,有沒有好的想法可以建議ㄧ下 謝謝 open(open_file, "12.txt") or "error file!!"; my $Out; my $name; while (<open_file>) { if ($_=~ m/^cell/g) { if ($_=~ /\s(.*\b.)/) { $name=$1; open(write_file, ">$name.txt") or "error file!!"; } print $_; print write_file $_; $Skip= 1; next; } if ($Skip==1) { $Out .=$_; print $_; print write_file $_; } if ($_=~ m/^}/g) { $Skip=0; next; close write_file; } } close open_file;my $Skip; ######---------12.txt---------###### library(std_ff) { /*general attributes */ delay_molel : table_lookup; in_palce_swap_mode : match_footprint; cell (DFADDS1) { cell_footprint : addf; area : 126.7200; pin(A) { direction : input; capacitance : 0.00975; } pin(B) { direction : inoutput; capacitance : 0.1975; } pin(CI) { direction : utput; capacitance : 0.1980; } } cell (DFADDS2) { cell_footprint : addf; area : 126.7200; pin(A) { direction : input; capacitance : 0.88975; } pin(B) { direction : inoutput; capacitance : 0.1900; } pin(CI) { direction : utput; capacitance : 0.1080; } } cell (DFADDS2) { cell_footprint : addf; area : 126.7200; pin(A) { direction : input; capacitance : 0.88975; } pin(B) { direction : inoutput; capacitance : 0.1900; } pin(CI) { direction : utput; capacitance : 0.1080; } } cell (DFADDS4) { cell_footprint : addf; area : 126.7200; pin(A) { direction : input; capacitance : 0.86975; } pin(B) { direction : inoutput; capacitance : 0.1902; } pin(CI) { direction : utput; capacitance : 0.0080; } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.176.59
drm343:把 /\S(.*\b.)/ 改成 /\S(\(.*\b.\))/ 有用嗎? 05/02 00:06
iloveyoungae:to drm大,那個方法好像不行耶~~~ 05/02 09:27
drm343:抱歉,忘了這是 Perl 用的,應該是 /\S((.*\b.*))/ 05/02 19:31
drm343:話說把 \b 改成 \w+ 好像會更好取? 05/02 19:43
iloveyoungae:drm大,好像還是有點怪怪的耶~ 05/03 09:09
iloveyoungae:改成 / *\((\w+)\)/i) 就ok了 05/03 14:46