Chinaunix首页 | 论坛 | 博客
  • 博客访问: 67155
  • 博文数量: 17
  • 博客积分: 673
  • 博客等级: 中士
  • 技术积分: 150
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 16:48
文章分类

全部博文(17)

文章存档

2012年(5)

2011年(12)

分类: LINUX

2011-06-22 16:46:39

This is commonly known as the 'Schwartzian Transform', as it was first discussed in detail by Randal Schwartz in a column of Unix Review。List file name sorted by the file contains how many lines of 'perl'.
    1. my @pairs = map { [ $_, count_perls($_) ] } @filenames;
    2. my @sorted_pairs = sort { $a->[1] <=> $b->[1] } @pairs;
    3. my @sorted = map { $_->[0] } @sorted_pairs;
    sub count_perls {
  1.  local $_; # Avoid clobbering caller's $_ 
  2.  my ($filename) = @_; my $count = 0; 
  3.  open(FH, "<", $filename) or die "Cannot open $filename - $!\n";
  4.  while () { 
  5.  $count++ if /Perl/i; } 
  6.  close(FH); 
  7.  return $count;
  8.  }
阅读(1611) | 评论(0) | 转发(0) |
0

上一篇:'{}', '()' in shell

下一篇:perl misc

给主人留下些什么吧!~~