I guess you must be in a part of the world that is already in 2006, so Happy New Year to you as well!

As you said, the two arrays have the same number of elements, so if you are just accessing all of the elements of each array in turn, there is no reason why you should be accessing uninitialized elements. The problem is this:

for (0..@weights)
That for loop will count one past the last element in the array, because the scalar value of @weights is the number of elements in the array, not the index of the last element. You should change this to:
for (0..$#weights)
To be really, really sure, you could do this:
for ($[..$#weights)
To go from the first element to the last element, but in sane code, $[ is always supposed to be 0 anyway, so I wouldn't bother with it.

In reply to Re: A better way than || by Celada
in thread A better way than || by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.