作者iloveyoungae (迷上西方天使)
看板Perl
標題[問題] 除了關鍵字,其餘改成大寫
時間Fri Apr 23 13:02:39 2010
各位先輩大家好
小弟最近開始練習一個題目
讀一個檔案,將關鍵字以外的字串,都變成大寫
這是小弟的寫法
use strict;
open(open_file "02.txt") or "error file!!";
open(write_file, ">04.txt") or "error file!!";
while(<open file>)
{
chomp;
if ($_ !~/input\s|module\s/i)
{
$_=~ tr/a-z/A-Z;
}
print write_file "$_","\n";
}
但是結果出來,有點問題
module wait68k (lbus , lcs_n , mode_68k ,
IOIS16_N , PDOE , WE_N , LBUS_N , OE_N,
LOAD_N , MIIDIOEN1 , PDOE_N );
input lbus;
input lcs_n;
input mode_68k;
input iois16_n;
input pdoe;
input we_n;
input lbus_n;
input oe_n;
OUTPUT LOAD_N;
OUTPUT MIIDIOEN1;
OUTPUT PDOE_N;
像是module跟input後面,應該要變成大寫,卻還是跟原本一樣,沒有改變
請教 這個問題該怎麼處理
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.220.246.245
→ crazydogx:/input\s|module\s <- 這是指「只要該行字出現input或 04/23 19:21
→ crazydogx:module這2個字,整行字就不用全變成大寫;否則就全變 04/23 19:22
→ crazydogx:大寫」吧? 04/23 19:23
→ crazydogx:/input\s|module\s/i (1F沒打好) 04/23 19:23
→ crazydogx:一種作法是先將整行字變大寫,然後把module和input變小 04/23 19:39
→ crazydogx:另一種是將input或module和其它字分開來,然後分別處理 04/23 19:40
→ crazydogx:Google: "Perl built-in function"找可以用的function 04/23 19:42
→ iloveyoungae:謝謝C大的建議!! 04/26 18:04