我必须打开一个csv文件并以hash的形式给出我的输出。我已经完成了那部分,现在我需要将我的文件的所有内容放入变量减去重复。 我怎么能这样做....
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 :(得分:0)
尝试执行此操作以删除数组中的重复项并将其转换为字符串:
sub uniq {
return keys %{{ map { $_ => 1 } @_ }};
}
my $string = join " ", uniq @my_array;
print $string;