0

我必须打开一个 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";

}
4

1 回答 1

0

尝试这样做以删除数组中的重复项并将其转换为字符串

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

my $string = join " ", uniq @my_array;
print $string;
于 2013-02-19T18:16:38.737 回答