Getting a report of "uninitialized value" could be a problem with how the "blocks" array is being created/filled in the first place -- no gaurantee that the cause of that error will be found in this portion of your code.

Apart from that, it will be better for you to try dereferencing the values that you need for doing the distance arithmetic before you actually do the arithmetic -- that way, when you hit the "uninitialized" error, it will be on a specific line of code where you are trying to dereference a particular value, and then it will be possible to trace back to where you thought that value was being stored (but in fact was not).

Also, it looks like you've been using the "copy/paste" approach to programming -- almost never a good idea, because (1) it means you're not factoring the problem properly to reduce redundant code and (2) you'll sometimes forget to make the small changes relative to the chunk that you copied from, or you'll make the wrong changes. In this case, the values being used in that lengthy "sqrt(...)" call are all the same, and if you didn't have an array reference problem, you'd have a math error (can't do sqrt on zero).

Let's see if I can paraphrase what you're trying to do here -- note that this is how I would begin any perl script: start with commentary to describe what's going on:

# * GIVEN: an AoAoA (@blocks), where: # -- the outermost index is (I think) a set of objects (?), # ---- the second index is a set of vertices for each object, # ------ the third index is a set of six values for each vertex: # ID(?), x, y, z(?), type-flag, another-flag(?), yet-another-flag(?). # When the type-flag is "88888", this is a solid vertex. # * TO DO: go through the vertices of each object in sequence # -- if the vertex is solid, store its x,y coordinates in @base # -- otherwise, store its x,y coordinates in $remote[0] (AoA) and: # ---- looking ahead while next vertex is also not solid, # push next set of coordinates onto @remote # ---- if more than one set of coordinates in @remote: # ------- foreach (@remote) # ---------- compute distance from @base and push it onto this x,y arr +ay # ------- for the elements of @remote sorted by distance: # --------- copy the coordinates from this element back to # the current vertex of @{$blocks[$thisObj]} # --------- increment to the next vertex in @{$blocks[$thisObj]}
Of course, there are other ways to go about it, but if I understand your post, this approach should do what you want, and I hope the description is clear enough that you can see the way to code it.

In reply to Re: Building an array by graff
in thread Building an array by stu96art

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.