Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

perl - Use of uninitialized value $elements[6] in pattern match (m//)

I am trying to run a MitoSite software which is written in Perl. I am not very familiar with perl scripting, and I get the following error:

needLargeMem: trying to allocate 0 bytes (limit: 100000000000)
Use of uninitialized value $elements[6] in pattern match (m//) at MitoSAlt1.1.pl line 221, <CONFIG> line 75.

I guess I have to change something in this piece, but I have no clue since I do not understand it well.

sub check_paired{
  my $check_paired = 0;
  my $path = shift;
  my $line = `zcat $path|tail -n 1`;
  my @elements = split(//, $line);

  $check_paired = 1 if $elements[6]=~m//.$/;
  return $check_paired;
}
question from:https://stackoverflow.com/questions/66064793/use-of-uninitialized-value-elements6-in-pattern-match-m

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The "uninitialized" message is a warning that means that the @elements array has fewer than 7 items in it. You could avoid that warning by checking how many items are in the array before you check the item at index 6:

sub check_paired{
  my $check_paired = 0;
  my $path = shift;
  my $line = `zcat $path|tail -n 1`;
  my @elements = split(//, $line);

  if (@elements > 6) {
      $check_paired = 1 if $elements[6]=~m//.$/;
  }
  return $check_paired;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...