我目前正在编写一个将文件作为输入的脚本。输入文件如下所示:
ECHANTILLON GENOTYPE
CAN1 genotype1
CAN2 genotype1
CAN3 genotype1
EUG1 genotype2
EUG2 genotype2
EUG3 genotype2
EUG4 genotype2
我想要做的是创建一个哈希:
- 作为 GENOTYPE 列的第一个键和
- 第二个名为“sample”的键将指向“ECHANTILLON”列。因此,它的值将给出例如 CAN1、CAN2...
这是我的脚本的样子:
#!/usr/local/perl-5.24.0/bin/perl
use warnings;
use strict;
use Data::Dumper;
use feature qw{ say };
use Getopt::Long;
my $list_geno;
GetOptions("g|input=s"=>\$list_geno);
my %hash_geno_group;
open(GENOTYPED,"<$list_geno") or die ("Cannot open $list_geno\n");
while (defined(my $l1= <GENOTYPED>))
{
my @geno_group_infos = split(m/\t/,$l1);
next if ($l1 =~ m/^ECHANTILLON/);
chomp($l1);
my $sample_nm = $geno_group_infos[0];
my $sample_geno_group = $geno_group_infos[1];
push @{ $hash_geno_group{$sample_geno_group}{"sample"} },$sample_nm;
foreach $sample_geno_group (keys (%hash_geno_group)){
foreach $sample_nm (values %{$hash_geno_group{%{$sample_geno_group}{"sample"}}}){
print $sample_geno_group, "\t" , $sample_nm, "\n";
}
}
}
close(GENOTYPED);
exit;
我试图检查什么返回 $sample_nm 变量的打印,但它返回我作为一个错误
Can't use string ("genotype1") as a HASH ref while "strict refs" in use at Test.pl line 27, "GENOTYPED" line 2".
谁能解释一下:
- 为什么我确实有这种类型或错误;
- 如何从第一列获取值。我需要进一步将它们存储到另一个变量中,以便将它们与相同的值进行比较,但来自另一个输入文件。谢谢 !