Chinaunix首页 | 论坛 | 博客
  • 博客访问: 41509
  • 博文数量: 19
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 145
  • 用 户 组: 普通用户
  • 注册时间: 2013-07-24 14:45
文章分类

全部博文(19)

文章存档

2018年(1)

2017年(6)

2016年(1)

2014年(11)

我的朋友

分类: PERL

2014-10-06 10:11:28

  • Consider finding the union and intersection of two unique arrays @a and @b:
        foreach $e (@a) { $union{$e} = 1 }
        foreach $e (@b) {
            if ( $union{$e} ) { $isect{$e} = 1 }
            $union{$e} = 1;
        }
        @union = keys %union;
        @isect = keys %isect;
  • This would be more idiomatically written as:
        foreach $e (@a, @b) { $union{$e}++ && $isect{$e}++ }
        @union = keys %union;
        @isect = keys %isect;
阅读(1317) | 评论(0) | 转发(0) |
0

上一篇:Perl Buffering

下一篇:Print perl source code

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