我有這樣如何創建數組的哈希在Perl
Group AT1G01040-TAIR-G
LOC_Os03g02970 69%
Group AT1G01050-TAIR-G
LOC_Os10g26600 85%
LOC_Os10g26633 35%
Group AT1G01090-TAIR-G
LOC_Os04g02900 74%
數據如何創建的數據結構,看起來像這樣:
print Dumper \%big;
$VAR = { "Group AT1G01040-TAIR-G" => ['LOC_Os03g02970 69%'],
"Group AT1G01050-TAIR-G" => ['LOC_Os10g26600 85%','LOC_Os10g26633 35%'],
"Group AT1G01090-TAIR-G" => ['LOC_Os04g02900 74%']};
這是我的嘗試,但失敗:
my %big;
while (<>) {
chomp;
my $line = $_;
my $head = "";
my @temp;
if ($line =~ /^Group/) {
$head = $line;
$head =~ s/[\r\s]+//g;
@temp =();
}
elsif ($line =~ /^\t/){
my $cont = $line;
$cont =~ s/[\t\r]+//g;
push @temp, $cont;
push @{$big{$head}},@temp;
};
}
爲什麼不產生哈希數組哈希?所以你的數據結構就像:'AT1G01040-TAIR-G'=> [{'LOC_Os03g02970'=> 69}](如果你需要對它們進行一些計算,或者將它們存儲在xml或...中? ) –