uninitialized value seems initialized
Fisch
created: 2006-08-04 05:11:06
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, 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, $symbol);
 99:  for ($lines=$pointers{respt}[0]; $lines<=$pointers{respt}[1]; $lines ++) {
100:    push @respt, (unpack (("A8" x (length($file[$lines]) / 8)), $file[$lines]));
101:  }
104:  my ($n, $r) = (0, 0);
105:  for $n (0 .. $#masses) {
109:    if ($n == ($respt[$r]-1)) {
110:      $r++;
111:    }
Re: uninitialized value seems initialized
created: 2006-08-04 05:18:05

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;
Re^2: uninitialized value seems initialized
created: 2006-08-04 05:40:35
You are right! My @respt is missing one entry. Thanks for your immediate response and help!

perlmonks.org content © perlmonks.org and Corion, Fisch

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03