Perl:Perl的一些应用例子。

1. 如何把一个字符串中的所有大写字符转成小写?

my $name="I am John";
$name=~s/[A-Z]*/\L$&/g;
print $name;

 转成小写:

$name=~s/[a-z]*/\U$&/g;

 2. 给函数传多个哈希值。

sub printh(%%)
{
  print @_;
}

my %h1 = ('a',1,'b',2,'c',3);
my %h2 = ('d',4,'e',5,'f',6);

printh(%h1, %h2);

 3. for循环的一个特殊例子:

for ($_="good";s/(.)//;) {
  print "One character is: $1\n";
}

 

posted @ 2014-10-01 17:35  zuiaishenlin  阅读(295)  评论(0)    收藏  举报