Fisch has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I have some code (listed below) within a module that does behave as it should but leads to error messages:

Use of uninitialized value in subtraction (-) at /usr/lib/perl5/site_perl/5.8.5/Chemistry/File/AMBERprmtop.pm line 109, <GEN0> line 1044. at /usr/lib/perl5/site_perl/5.8.5/Chemistry/File/AMBERprmtop.pm line 109

I cannot see what value is not initialized: $n and $r are initialized in line 104, $respt[$r] is part of @respt which is initialized in line 80.

Am I missing something? (Sure, I do...) Any hints are welcome! Thanks for your help.


80: my ($lines, @masses, @names, @charges, @resnames, @respt, $symbo +l); 99: for ($lines=$pointers{respt}[0]; $lines<=$pointers{respt}[1]; $l +ines ++) { 100: push @respt, (unpack (("A8" x (length($file[$lines]) / 8)), $f +ile[$lines])); 101: } 104: my ($n, $r) = (0, 0); 105: for $n (0 .. $#masses) { 109: if ($n == ($respt[$r]-1)) { 110: $r++; 111: }

Replies are listed 'Best First'.
Re: uninitialized value seems initialized
by Corion (Patriarch) on Aug 04, 2006 at 09:18 UTC

    You're confusing declaration and initialization. @respt is declared in line 80, but likely, not all elements of @respt are initialized in line 99, or rather, not enough elements. To further debug this, print out the number of elements in @respt:

    #line 102 print "Elements in \@respt: ", scalar @respt;
      You are right! My @respt is missing one entry. Thanks for your immediate response and help!