Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1272746
  • 博文数量: 213
  • 博客积分: 7590
  • 博客等级: 少将
  • 技术积分: 2185
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-31 17:31
个人简介

热爱开源,热爱linux

文章分类

全部博文(213)

文章存档

2018年(4)

2017年(1)

2015年(1)

2014年(5)

2013年(2)

2012年(2)

2011年(21)

2010年(82)

2009年(72)

2008年(23)

分类: Python/Ruby

2011-04-20 15:58:43

  1. #!/usr/local/perl
  2. # Author :ceagle
  3. # Date:2011-04-20
  4. # Desc:The script is just test map function in perl
  5. # Version 0.1

  6. use warnings;
  7. use strict;
  8. my @str = ("hello" ,"world" ,"ni hao","I love China");
  9. print join("\t",@str);
  10. print "\n";
  11. my @upper_str = map uc, @str; #Capital of the entire array of elements
  12. print join("\t",@upper_str);
  13. print "\n";
  14. my @first_word = map {/(\S+)/} @str;#将一个语法规则映射到字符串数组返回每个短语的首字
  15. print join("\t",@first_word);
  16. print "\n";
  17. my @words = map split , @str;#将每个短语拆分成一个个单词
  18. print join("\t",@words);
  19. print "\n";
  20. # 将所有的字符串小写后将第一个单词的首字母大写
  21. my $title = "welcome TO chIna!";
  22. my $final_title = join '',map {ucfirst lc} split ,$title;
  23. print "$final_title\n";
  24. my %hash = (1=>"hello",2=>"world",3=>"ni",0=>"ceagle welcome");
  25. foreach my $key (sort keys %hash) {
  26. print "$key\t==>\t $hash{$key}\n";
  27. }
  28. my $hash;
  29. print "###############################################\n";
  30. print map {"$_ \t==>\t $hash{$_}\n"} sort keys %hash;
  31. print "###############################################\n";
阅读(1740) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

caojiangfeng2011-07-30 22:07:29

cinanine: 握手握手.....

cinanine2011-07-24 15:43:22

握手握手