Well, the first thing wrong with your code is that you start with empty arrays, and the only place where anything is pushed into these arrays is inside a loop over the array elements:  for $value (@array) -- and since there are no array elements to start with, the push call is never reached.

Apart from that, there seems to be a disconnect between your stated purpose and the design of your code, and there are some pending questions. How many characters do you plan to draw? Given a 250x250 (pixel) space, the characters will overlap more or less quickly (depending on the font size you're using), even though you don't re-use the same coordinates. If there is a limited number of characters to draw, you could "pre-select" a random set of coordinates by generating an x array and a y array of equal size (number of elements == number of characters to draw), making sure that each array is limited to unique values (something similar to suggestions provided in this thread: Select three random numbers between 1..10

On the other hand, wouldn't it be okay if you use the same x or y coordinate more than once, so long as you don't repeat any given combination of x and y? If so, then you should be keeping a hash whose keys are strings like "123 78" -- that is, just the x and y integer values for a drawn letter, separated by a space. If you pick any two integers at random, it's very unlikely that it would match an existing point, but if it does, you'll find out quickly by testing  if ( exists( $drawn{"$xco $yco"} ))

update: Oh yeah -- and that logic error that Mr. Muskrat alluded to... ooooh, it's quite the unpleasant sort. Look at your "for" loops, imagine that you start out with three values in @xco, and you have a fourth new random x coordinate (which happens not to match the other three). How many pushes do you want to do into @xco? And how many will actually be done by the code you've posted?


In reply to Re: Array remains empty by graff
in thread Array remains empty by witandhumor

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.