Perl中对字符串的大小写转换
发布者: Ulric 发布时间: 2012-10-08 13:06 阅读: 686 次 原文链接转自Perl中对字符串的大小写转换
在perl中,我们可以通过uc,lc,\U,\L来修改变量的大小写。其中uc,\U是将变量中的字母全部转换为大写,对应的lc和\L是将变量中的字母全部转换为小写。如果我们只想将变量的首字母大写或将变量的首字母小写,我们可以使用perl提供给我们的另外两个函数ucfirst和lcfirst来实现,下面我们来看一个具体的例子:
#! /usr/bin/perl -wmy $str ="Hello,this is Ulric";print":".uc($str)."\n";print":".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($str)."\n";print":".lcfirst($str)."\n";#output:#:HELLO,THIS IS ULRIC#:hello,this is ulric#[\U]:HELLO,THIS IS ULRIC#[\u]:Hello,this is Ulric#[\L]:hello,this is ulric#[\l]:hello,this is Ulric#:Hello,this is Ulric#:hello,this is Ulric
http://www.coderroad.com/blog/40/perl-upper-lower-uc-lc
页:
[1]