Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1629221
  • 博文数量: 126
  • 博客积分: 1541
  • 博客等级: 上尉
  • 技术积分: 1914
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-20 11:14
文章分类

全部博文(126)

文章存档

2014年(21)

2013年(42)

2012年(63)

分类: Python/Ruby

2012-11-24 11:51:01

$# 最后一个数组元素的索引
yangfeng@sbuild:~/python$ cat pe.pl
#!/usr/bin/perl
$string="This string contains the number 25.12";
$string=~ /(\d )\.(\d )/;
print "$string\n";
print "$1\n";
print "$2\n";
print "$&\n";
yangfeng@sbuild:~/python$ ./pe.pl 
This string contains the number 25.12
25
12
25.12

在perl中,我们可以通过uc,lc,\U,\L来修改变量的大小写。其中uc,\U是将变量中的字母全部转换为大写,对应的lc和\L是将变量中的字母全部转换为小写。如果我们只想将变量的首字母大写或将变量的首字母小写,我们可以使用perl提供给我们的另外两个函数ucfirst和lcfirst来实现,下面我们来看一个具体的例子:
yangfeng@sbuild:~/python$ cat perl.pl
#!/usr/bin/perl
print "this is my first perl program\n";
$a=<>;

print $a;
my $big =uc($a);
my $litter=lc($a);
print $big;
print $litter;
print ucfirst($a);
print lcfirst($a);
yangfeng@sbuild:~/python$ ./perl.pl 
this is my first perl program
YANGfeng  
YANGfeng
YANGFENG
yangfeng
YANGfeng
yANGfeng
yangfeng@sbuild:~/python$ 



阅读(742) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~