>>>>> "DL" == Donald Leslie {74279} <[EMAIL PROTECTED]> writes:

  DL> Use of uninitialized value in string eq at
  DL> /usr/lib/perl5/site_perl/5.8.5/XML/Generator/DBI.pm line 187

  DL>         my $ind = 0;
  DL>          while ($el_stack[$ind] eq $stack[$ind] and
  DL>                 $ind <= $stack_len and
  DL>                 $ind <= $el_stack_len)
  DL>          {
  DL>              $ind ++;
  DL>          }

  DL> Line 180 is the while statement

first off, use && over 'and' for boolean tests. the rule i use (and i
stole from peter scott) is &&/|| for expressions and and/or when you are
doing flow control.

the way i debug uninitialized errors is to print everything in single
print statements (so the line numbers tell you which things is
undef). so put these inside the while:

warn "EL [$el_stack[$ind]]" ;
warn "ST [$stack[$ind]]" ;
warn "ST LEN [$stack_len]" ;
warn "EL LEN [$el_stack_len]" ;

we don't see how the stack length vars are set. assuming they are length
as you say, then you are off by one. an array with length 3 will have a
maximum index of 2. the <= comparisons are wrong then - they should be
<.

even if your arrays were size properly, the logic of the loop is
suspect. you check the values before you check the indexes. if the
indexes are too large you may/will check a non-existing value on the
last iteration (another off by one error). so put the index tests before
the value tests and let short circuiting do that for you.

finally, what is the purpose of that loop? is it to check equality of
the arrays or to find the first element that is different? there are
modules which can do this sort of thing.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to