2013-02-19 131 views
0

我必須打開一個csv文件,並以散列形式給出我的輸出。我已經完成了這部分,現在我需要將我的文件的所有內容放入一個變量減去重複。 我怎樣才能做到這一點....如何從CSV文件中刪除重複值?

open FILE, " < abc.csv" or die $!; 
# Reading content from CSV file 
my @genes = <FILE>; 
# Removing the information header from the CSV file contents 
shift (@genes); 

print "my %hash = (\n"; 

foreach(@genes){ 
    chomp; 
    my @genes = split(':',$_); 
    if(@genes != 25){ 
     next; 
    } 

    my $amino_acid = join('","',split(/,/,$genes[4]));  


    print "$genes[2]=> [$genes[0],$genes[1],[$group]],\n"; 

} 
+0

你似乎感到困惑哪個數組你什麼時候用。 '@genetic_codes'和'@ genes'。也許你應該在發佈代碼之前決定如何使用它們,並避免發佈無用的代碼。 – TLP 2013-02-19 18:27:35

+1

您試圖將存儲格式從csv更改爲perl代碼的意圖是什麼? Perl代碼不是序列化數據的最佳方式。 – TLP 2013-02-19 18:28:50

+0

模糊標題不可能對未來的訪問者有用。 – 2013-02-19 18:50:03

回答

0

嘗試這樣做是爲了消除重複在陣列並將其在字符串變換:

sub uniq { 
    return keys %{{ map { $_ => 1 } @_ }}; 
} 

my $string = join " ", uniq @my_array; 
print $string;