作者iloveyoungae (迷上西方天使)
看板Perl
标题[问题] 如何取得()内不定长度的字串
时间Sat May 1 16:59:19 2010
大家好
小弟最近在练习ㄧ个题目
将.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
1F:→ drm343:把 /\S(.*\b.)/ 改成 /\S(\(.*\b.\))/ 有用吗? 05/02 00:06
2F:→ iloveyoungae:to drm大,那个方法好像不行耶~~~ 05/02 09:27
3F:→ drm343:抱歉,忘了这是 Perl 用的,应该是 /\S((.*\b.*))/ 05/02 19:31
4F:→ drm343:话说把 \b 改成 \w+ 好像会更好取? 05/02 19:43
5F:→ iloveyoungae:drm大,好像还是有点怪怪的耶~ 05/03 09:09
6F:→ iloveyoungae:改成 / *\((\w+)\)/i) 就ok了 05/03 14:46