-1

我正在做一个程序,它使用变量组合(combiData.txt 63 行 x 不同的列数)来分析数据表(j1j2_1.csv, 1000filas x 19 列),以选择每个组合在数据中重复的次数表以及来自哪些行(例如,tableData[row][4])。

我试图编译它,但是我收到以下消息:

  Use of uninitialized value $val in numeric eq (==) at rowInData.pl line 34.
  Use of reference "ARRAY(0x1a2eae4)" as array index at rowInData.pl line 56.
  Use of reference "ARRAY(0x1a1334c)" as array index at rowInData.pl line 56.
  Use of uninitialized value in subtraction (-) at rowInData.pl line 56.
  Modification of non-creatable array value attempted, subscript -1 at rowInData.pl line 56.
nothing


这是我的代码:

      #!/usr/bin/perl
      use strict;
      use warnings;

      my $line_match;
      my $countTrue;

       open (FILE1, "<combiData.txt") or die "can't open file text1.txt\n";
       my @tableCombi;
       while(<FILE1>) {
       my @row = split(' ', $_);
       push(@tableCombi, \@row);
       }
       close FILE1 || die $!;

       open (FILE2, "<j1j2_1.csv") or die "can't open file text1.txt\n";
       my @tableData;
       while(<FILE2>) {
          my @row2 = split(/\s*,\s*/, $_);
       push(@tableData, \@row2);
       }
       close FILE2 || die $!;

      #function transform combiData.txt variable (position ) to the real value that i have to  find in the data table.
      sub trueVal($){
      my ($val) = $_[0];
      if($val == 7){ return ('nonsynonymous_SNV'); }
      elsif( $val == 14)          { return '1'; }
      elsif( $val == 15)   { return '1';}
      elsif( $val == 16)    { return '1'; }
      elsif( $val == 17)        { return '1'; }
      elsif( $val == 18)      { return '1';}
      elsif( $val == 19)     { return '1';}
      else              { print 'nothing'; }
      }

     #function  IntToStr ( ) , i'm not sure if it is necessary) that transforms $ to strings  ,     to use the function <eq> in the third loop for the array of combinations compared with the data  array .
     sub IntToStr { return "$_[0]"; } 



     for my $combi (@tableCombi) {
     $line_match = 0;

         for my $sheetData (@tableData) {
        $countTrue=0;

       for my $cell ( @$combi) {
             #my $temp =\$tableCombi[$combi][$cell] ;
         #if ( trueVal($tableCombi[$combi][$cell] )  eq $tableData[$sheetData][ $tableCombi[$combi][$cell] - 1 ]   ){
         #if ( IntToStr(trueVal($$temp )) eq IntToStr( $tableData[$sheetData][ $$temp-1] ) ){
         if ( IntToStr(trueVal($tableCombi[$combi][$cell]) )  eq IntToStr($tableData[$sheetData][ $tableCombi[$combi][$cell] -1])  ){
            $countTrue++;}
         if ($countTrue==@$combi){
            $line_match++;
            #if ($line_match < 50){
            print $tableData[$sheetData][4]." ";
            #}
         }  

     }
  }
print $line_match." \n";
 }
4

2 回答 2

0

首先,我会在应该退回的情况下return(0);添加。trueVal()只是更好读。

但是,您的主要问题似乎是第 52 行(说真的,如果您希望人们理解您的错误消息,请添加行号)。@$combi是一个数组参考。不是数组。顺便说一下,正如错误消息明确指出的那样。我假设您希望它是单词的数组$combi?如果是这样,只需添加另一行

my @combiArray = split (/ +/, $combi);

并对其进行$cell迭代。/ +/如果这些条目由不同于一个或多个空格的内容分隔,则替换。确实可能有一种方法可以在同一行中进行归档,但仅仅因为 Perl 允许将多个操作放在一行中并不意味着您必须这样做。

于 2013-10-22T06:54:50.337 回答
0

使用此代码:

for my $combi (@tableCombi) {
     $line_match = 0;
     for my $sheetData (@tableData) {
         $countTrue=0;
         for my $cell ( @$combi) {

您正在迭代值,而不是数组的索引。

你应该做:

for my $combi (@tableCombi) {
     $line_match = 0;
     for my $sheetData (@tableData) {
         $countTrue=0;
         for my $cell ( @$combi) {
             if (IntToStr(trueVal($cell)) eq IntToStr($sheetData->[$cell-1])){
                 $countTrue++;
             }
             if ($countTrue == @$combi){
                 $line_match++;
                 print $tableData[$sheetData][4]." ";
             }  
         }
     }
}
于 2013-10-22T07:16:47.453 回答