我正在尝试创建23个数组而不键入@array1,@array2依此类推,@r如果$chrid匹配数组编号(如果$chrid=1应该放入@array1),则使用数组中的变量加载它们.我怎样才能做到这一点?
这是我到目前为止:
#!/usr/bin/perl
use warnings;
use strict;
my @chr;
my $input;
open ($input, "$ARGV[0]") || die;
while (<$input>) {
my @r = split(/\t/);
my $snps = $r[0];
my $pval = $r[1];
my $pmid = $r[2];
my $chrpos = $r[3];
my $chrid = $r[4];
for ($chrid) {
push (@chr, $chrid);
}
}
close $input;
Run Code Online (Sandbox Code Playgroud)
您可以使用数组数组,其中每个子数组都存储在数组数组中的顺序递增索引处.这可能是什么样的,但我仍然不清楚你想要存储的数据:
use warnings;
use strict;
my @chr;
open my $input_fh, '<', $ARGV[0]
or die "Unable to open $ARGV[0] for reading: $!";
while (< $input_fh> ) {
# you can unpack your data in a single statement
my ($snps, $pval, $pmid, $chrpos, $chrid) = split /\t/;
# unclear what you actually want to store
push @{ $chr[$chrid] }, ( $snps, $pval, $pmid, $chrpos, $chrid );
}
close $input_fh;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
237 次 |
| 最近记录: |