作者toolate (我是87一个)
看板Perl
标题[请益] 有条件式的取代字串
时间Thu Mar 12 09:44:05 2009
假设我的档案中有n行 由.inc 开头的行列
然後 我只想将这 n行中 由TT 结尾的,改成.include开头
用了
while ($line=<file>) {
$line=~ s/.inc (TT$)/.include/g ;
push(@out,$line);
}
但对於那些TT结尾的 还是不会取代
请问我可以怎麽改
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 192.94.35.2
1F:→ toolate:在/g後面 改为/eg 会出现 compilation error 03/12 09:49
2F:→ deh3215:分两段写可以吧 if($_ =~ /TT$/) { 03/12 11:35
3F:→ deh3215:$_ =~ s/.inc/.include/gs; 03/12 11:36
4F:→ deh3215:档案内容是这样吗 .incxxxxxxTT ? 我也算新手,互相切磋吧 03/12 11:37
5F:→ toolate:目前是用了 s/.lib (.*)(\s+TT\s*)/.include/g 03/12 11:37
6F:→ toolate:档案是.inc 'xxxxxxxxx' TT 03/12 11:37