作者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
1F:→ crazydogx:/input\s|module\s <- 这是指「只要该行字出现input或 04/23 19:21
2F:→ crazydogx:module这2个字,整行字就不用全变成大写;否则就全变 04/23 19:22
3F:→ crazydogx:大写」吧? 04/23 19:23
4F:→ crazydogx:/input\s|module\s/i (1F没打好) 04/23 19:23
5F:→ crazydogx:一种作法是先将整行字变大写,然後把module和input变小 04/23 19:39
6F:→ crazydogx:另一种是将input或module和其它字分开来,然後分别处理 04/23 19:40
7F:→ crazydogx:Google: "Perl built-in function"找可以用的function 04/23 19:42
8F:→ iloveyoungae:谢谢C大的建议!! 04/26 18:04