我正在尝试编写一个大脚本,但我陷入了困境。我想基于“ ..”的数组从脚本中我得到了:
print @coordinates;
gene complement(872..1288)
我想要的输出:
complement 872 1288
我尝试过:
1) my @answer = split(.., @coordinates)
print("@answer\n");
2) my @answer = split /../, @coordinates;
3) print +(split /\../)[-1],[-2],[-3] while <@coordinates>
4) foreach my $anwser ( @coordinates )
{$anwser =~ s/../"\t"/;
print $anwser;}
5) my @answer = split(/../, "complement(872..1288)"); #to see if the printed array is problematic.
which prints:
) ) ) ) ) ) ) ) )
6) my @answer = split /"gene "/, @coordinates; # I tried to "catch" the intire output's spaces and tabs
which prints
0000000000000000000000000000000001000000000100000000
但是它们都不起作用。有谁知道如何解决这个问题?ps,不幸的是,我现在无法在Linux上运行我的脚本,因此我使用此website运行我的脚本。我希望这不是我没有得到理想输出的原因。
[split在标量上运算,而不在数组上。
my $string = 'gene complement(872..1288)';
my @parts = split /\.\./, $string;
print $parts[0]; # gene complement(872
print $parts[1]; # 1288)