文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>A piece of perl code

A piece of perl code

时间:2010-04-09  来源:yk325

Perl

use Data::Dumper;

my %hash;

while(<DATA>){
    next if /^$/;
    my @array = split("<--",$_);
    
    my $array_length = $#array + 1;

    
    while($#array != 0){

        my $key = pop @array;
        if(! exists($hash{$key})){
            $hash{$key} = [ $array[-1] ];
        } else {
            next if ( grep { $_ eq $array[-1]} @{ $hash{$key} } );#if the item already exists in the array, skip it

            push @{ $hash{$key} }, $array[-1]; # put the item into the array if it does not exist in the array

        }
    }
}

print OFH Dumper(\%hash);


__DATA__

tt1 <-- tt2 <-- tt3 <-- tt4
tt1 <-- tt2 <-- tt3 <-- tt4


相关阅读 更多 +
排行榜 更多 +
边境检察最后区域手机版下载

边境检察最后区域手机版下载

角色扮演 下载
酋长你别跑手游下载

酋长你别跑手游下载

休闲益智 下载
心动漫画app下载官方版

心动漫画app下载官方版

浏览阅读 下载