I never liked searches, I remember doing an address book application in the mid 80's and routines for finding names in a big list were a pain. But I found if you are looking for efficiency sort your array first if possible. Now this really only applies if your data is in a format that this can work with. For my names db then, I would sort my list by surname on entry so the list was always in alphabetical order. Than when give a name you I would go the half way point and if the $string ascii values were less than the half way point go back half way. And so on homing in on the name. I found this achieved quick results. But it relies on the dataset being easily sortable.

This was in pascal and assembler and I have never really had to do anything since on the same scale because most datasets I work on now are coming from a Database Server which uses SQL to process the searches on that level. But I would think if the data is large enough and your searches happen often enough, you could build an index to use that you could than pull the values you need out of. Avoiding the overhead on the searches but adding the overhead on the data entry.

"No matter where you go, there you are." BB

In reply to Re: finding index number in an array by Ninthwave
in thread finding index number in an array 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.