看板 Perl 關於我們 聯絡資訊
假設我的檔案中有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
toolate:在/g後面 改為/eg 會出現 compilation error 03/12 09:49
deh3215:分兩段寫可以吧 if($_ =~ /TT$/) { 03/12 11:35
deh3215:$_ =~ s/.inc/.include/gs; 03/12 11:36
deh3215:檔案內容是這樣嗎 .incxxxxxxTT ? 我也算新手,互相切磋吧 03/12 11:37
toolate:目前是用了 s/.lib (.*)(\s+TT\s*)/.include/g 03/12 11:37
toolate:檔案是.inc 'xxxxxxxxx' TT 03/12 11:37