0

Given a certain sequence A stored in an array, I have to find if a larger sequence B contains sequence A.

I am stuck at the index part... and i'm getting an error that argument "TGACCA" isn't numeric in array element in line 69 which is:

if (index($record_r1[1], $r2_seq[$check]) != -1)


The code is:

foreach my $check (@r2_seq)
{
  if (index($record_r1[1], $r2_seq[$check]) != -1)
  {
     $matches= $matches + 1;
     print "Matched";
  }
  else
  {
  }
}
4

2 回答 2

3
foreach my $check (@r2_seq)

$check取 中每个元素的值@r2_seq。它不是索引。

$r2_seq[$check]

这是尝试将 的元素@r2_seq用作 的索引@r2_seq。这不太可能是您想要的。更有可能,您想使用

$check

如在

if (index($record_r1[1], $check) != -1)

.

于 2012-06-02T23:39:04.070 回答
0

我相信您想$check成为index,因此请使用以下代码:

foreach my $index (0..$#r2_seq)
{
  if (index($record_r1[1], $r2_seq[$index]) != -1)
  {
     $matches= $matches + 1;
     print "Matched";
  }
  else
  {
  }
}
于 2012-06-02T23:49:04.277 回答