在perl中,我们可以通过uc,lc,\U,\L来修改变量的大小写。其中uc,\U是将变量中的字母全部转换为大写,对应的lc和\L是将变量中的字母全部转换为小写。如果我们只想将变量的首字母大写或将变量的首字母小写,我们可以使用perl提供给我们的另外两个函数ucfirst和lcfirst来实现,下面我们来看一个具体的例子:
#! /usr/bin/perl -wmy $str ="Hello,this is Ulric";print"[uc]:".uc($str)."\n";print"[lc]:".lc($str)."\n";print'[\U]:'."\U$str\n";print'[\u]:'."\u$str\n";print'[\L]:'."\L$str\n";print'[\l]:'."\l$str\n";print"[ucfirst]:".ucfirst($str)."\n";print"[lcfirst]:".lcfirst($str)."\n";#output:#[uc]:HELLO,THIS IS ULRIC#[lc]:hello,this is ulric#[\U]:HELLO,THIS IS ULRIC#[\u]:Hello,this is Ulric#[\L]:hello,this is ulric#[\l]:hello,this is Ulric#[ucfirst]:Hello,this is Ulric#[lcfirst]:hello,this is Ulrichttp://www.coderroad.com/blog/40/perl-upper-lower-uc-lc