I have a field which takes values from 0 to 6,00,000. For this field values in database are say 5,6,7,8,45,91,92,93,94. I have to get free values and used value suggestions for this field. 1.USED Minvalue= 0 maxvalue=94( from database) i use a for loop (i=minvalue;i<=maxvalue;i++) Loop runs 94 times in this case and each time it checks if something matches database entries (5,6,7,45..94). I print output ranges like. Used values: 5 to 8 45 91 to 94 Since values are less it works fast. If there was even one entry like 490000 in database then loop would have run for a very long time. 2. FREE Min value= 0 maxvalue = 600000 (from field definition) I have the same for loop concept here too so the loop runs 500000 times. And output comes after a long time. It is too time consuming. I would want output like. Free values : 0 to 4 9 to 44 46 to 90 95-600000 Any way to reduce for loop executions or use some other logic.

In reply to For loop suggestions by sure_mp

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.