perl实例分析之一
时间:2006-03-08 来源:andyhua12
$text = "thIS is a loNG liNE";
$text =~ s/(\w+)/\u\L$1/g;
print $text;
This Is A Long Line
#-----------------------------
if (uc($a) eq uc($b)) {
print "a and b are the same\n";
} 作用:把所有单词的第一个字母大写,其余字母小写。 注释: \u强制下一个字母为大写字母 \L 强制后面所有字母为小写。 $1和前面()中的内容对应。 其他相关知识: \l \U \Q 所有后面的非字母数字字符加反斜杠
$text =~ s/(\w+)/\u\L$1/g;
print $text;
This Is A Long Line
#-----------------------------
if (uc($a) eq uc($b)) {
print "a and b are the same\n";
} 作用:把所有单词的第一个字母大写,其余字母小写。 注释: \u强制下一个字母为大写字母 \L 强制后面所有字母为小写。 $1和前面()中的内容对应。 其他相关知识: \l \U \Q 所有后面的非字母数字字符加反斜杠
相关阅读 更多 +