加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl数据结构的应用

发布时间:2020-12-16 00:17:14 所属栏目:大数据 来源:网络整理
导读:最简单的数据结构的应用,把相同id的行合并,涉及引用等知识: #!/usr/bin/env perluse warnings;use strict;my %hash;open FA,$ARGV[0] || die $!;while (FA){chomp;my @tmp = split;my $string = "$tmp[1]t$tmp[2]t$tmp[3]t$tmp[4]t$tmp[5]";push @{$h

最简单的数据结构的应用,把相同id的行合并,涉及引用等知识:

#!/usr/bin/env perl
use warnings;
use strict;

my %hash;
open FA,$ARGV[0] || die $!;
while (<FA>)
{
	chomp;
	my @tmp = split;
	my $string = "$tmp[1]t$tmp[2]t$tmp[3]t$tmp[4]t$tmp[5]";
	push @{$hash{$tmp[0]}},$string;
}
close FA;

foreach my $id (sort {$a cmp $b} keys %hash)
{
	if (@{$hash{$id}} == 1)
	{
		print "$idt$hash{$id}[0]n";
	}else{
		my ($ref,$sum);
		my (@colsum,@set);
		for(my $i = 0; $i < @{$hash{$id}}; $i ++)
		{
			@set = split /s/,$hash{$id}[$i];
			for(my $j = 0; $j < @set; $j ++)
			{
				$ref->[$i][$j] = $set[$j];
			}
		}
		for(my $j = 0; $j < @{$ref->[0]}; $j ++)
		{
			for(my $i = 0; $i < @{$ref}; $i ++)
			{
				$sum += $ref->[$i][$j];
			}
			push @colsum,$sum;
		}
		print join "t",$id,@colsum,"n";
	}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读