Arrays 如何在Perl数组中搜索更改每次迭代的字符串

Arrays 如何在Perl数组中搜索更改每次迭代的字符串,arrays,string,perl,search,hashtable,Arrays,String,Perl,Search,Hashtable,我看过文档,知道如何在数组中搜索字符串,打印字符串的位置,等等。但我的问题是每次迭代我的字符串都会改变。我的目标是在数组的第一行中搜索字符串,保存其位置,然后在数组的第一列中搜索其他字符串,并保存该位置(给我一个数组中的行、列位置)。以下是我想要执行的“想法”的代码: use strict; use warnings; my $subseq1 = 'MNIDDKL'; my $subseq2 = 'GLFLKCGGIDEMQSS'; my $line; my @array; my @arr; w

我看过文档,知道如何在数组中搜索字符串,打印字符串的位置,等等。但我的问题是每次迭代我的字符串都会改变。我的目标是在数组的第一行中搜索字符串,保存其位置,然后在数组的第一列中搜索其他字符串,并保存该位置(给我一个数组中的行、列位置)。以下是我想要执行的“想法”的代码:

use strict;
use warnings;
my $subseq1 = 'MNIDDKL';
my $subseq2 = 'GLFLKCGGIDEMQSS';
my $line;
my @array;
my @arr;
while($line = <MATFILE>) #Load the array
{
    $line =~ /^$/ and die "Blank line detected at $.\n";
    $line =~ /^#/ and next;
    push @array, $line; #adds each line to the array
};
close MATFILE;

#Join then split
my $joined = join('', @array);
my @rep = $joined =~/./g;
@rep = split(' ', $joined);

#Need to split into row, column format:
while (@rep)
{
    push (@arr, [splice(@rep, 0, 24)]);
}
my ($len1, $len2) = map length, $subseq1, $subseq2;
my @subseq1 = $subseq1 =~ /./g;
my @subseq2 = $subseq2 =~ /./g;
for my $x (0..$len2) #Number of rows
{
    for my $y (0..$len1) #Number of columns
    {
        if ($subseq1[$y] == $arr[0][$_]) #Does not work 
        {
        my $subcol = $_; #column from the sub matrix
        }

    if ($subseq2[$x] == $arr[$_][0]) #Does not work
        {
        my $subrow = $_; #row from pam matrix
        }
    }
}
我将访问这些值并使用它们计算序列相似性的分数。

my%score\u lookup;
my %score_lookup;
{
   my $found_header = 0;
   my @col_ids;
   while (<>) {
      next if /^#/;

      if ($found_header) {
         my ($row_id, @fields) = split;
         for my $i (0..$#fields) {
            my $col_id = $col_ids[$i];
            my $score = $fields[$i];
            $score_lookup{ $row_id . $col_id } = $score;
         }
      } else {
         $found_header = 1;
         @col_ids = split;
      }
   }
}

my $score = $score_lookup{ "A" . "R" };   # -2
{ 我的$found_头=0; 我的@col_id; 而(){ 下一个if/^#/; 如果($found\u头){ 我的($row\u id,@fields)=拆分; 对于我的$i(0..$#字段){ my$col_id=$col_id[$i]; 我的$score=$fields[$i]; $score_lookup{$row_id.$col_id}=$score; } }否则{ $found_头=1; @col_id=拆分; } } } 我的$score=$score_查找{“A”。“R”};#-2.
my%score\u查找;
{
我的$found_头=0;
我的@col_id;
而(){
下一个if/^#/;
如果($found\u头){
我的($row\u id,@fields)=拆分;
对于我的$i(0..$#字段){
my$col_id=$col_id[$i];
我的$score=$fields[$i];
$score_lookup{$row_id.$col_id}=$score;
}
}否则{
$found_头=1;
@col_id=拆分;
}
}
}
我的$score=$score_查找{“A”。“R”};#-2.

你能展示一些数据,并指出你需要从中得到什么部分吗?那么,对于{A,R},你想要-2吗?这是正确的@ikegamiA HoH比AoA更有意义,那么。事实上,我会使用一个由两个字母字符串组成的简单散列。
=
用于比较数字。您需要
eq
来比较字符串<代码>使用警告会告诉你的。你能展示一些数据,并指出你需要从中得到什么部分吗?那么,对于{A,R},你想要-2吗?这是正确的@ikegamiA HoH比AoA更有意义,那么。事实上,我会使用一个由两个字母字符串组成的简单散列。
=
用于比较数字。您需要
eq
来比较字符串<代码>使用警告会告诉你的。
my %score_lookup;
{
   my $found_header = 0;
   my @col_ids;
   while (<>) {
      next if /^#/;

      if ($found_header) {
         my ($row_id, @fields) = split;
         for my $i (0..$#fields) {
            my $col_id = $col_ids[$i];
            my $score = $fields[$i];
            $score_lookup{ $row_id . $col_id } = $score;
         }
      } else {
         $found_header = 1;
         @col_ids = split;
      }
   }
}

my $score = $score_lookup{ "A" . "R" };   # -2