+ -
当前位置:首页 → 问答吧 → 帮我看看这段字段统计的代码

帮我看看这段字段统计的代码

时间:2010-12-31

来源:互联网

本帖最后由 enigmain 于 2011-01-01 11:15 编辑

我有这么一段代码,是统计AU字段后面出现的人数

例如
AU: Demming, A
AF Demming, Anna


AU: Gaspar, VM
   Sousa, F
   Queiroz, JA
   Correia, IJ
AF Gaspar, V. M.
   Sousa, F.
   Queiroz, J. A.
   Correia, I. J.


AU: Abergel, DSL
   Chakraborty, T
AF Abergel, D. S. L.
   Chakraborty, Tapash

出来的结果应该是1,4,2,即只统计AU后面出现的人数,例如“Demming, A”逗号前是姓,逗号后是名。AF后面的不需要统计。
我当初写的代码是这样的:
my $count=();
while(<>){
    chomp;
    if(/^AU/){
        if($count){
            print $count,"\n";
            undef $count;
        }
        $count++;
    }elsif(/\s{2}\b(\w+)\b.{2}\b(\w+)\b$/){
        $count++;
    }
}
if($count){
    print $count,"\n";
    undef $count;
}
不知道哪里出问题了,出来的结果不对。请大家帮我看看啊,多谢!顺祝大家新年快乐!

作者: enigmain   发布时间: 2010-12-31

没看懂LZ的需求

作者: Cu_fans   发布时间: 2011-01-01