If you want to do an alphabetic search you can generally do a brute force approach (search every value) or set up an inverted index or tree, which would be really fast to search. An SQL database would probably do this for you so you could just use "LIKE" to search.

Regexes are also a way to do it; concatenate the whole thing together and then read off the rest of the entry.

Or a twist on the last suggestion, about using a hash. If you concatenate an incrementing number to the end of your keyword it will work even if you have keys with the same name. Just keep track of how many synonymous keys you have, using another hash (like synonyms{bob}==2 to tell you that $bighash{bob0} and $bighash{bob1} exist.

But these different strategies do kind of depend on why you are trying to do what you are doing. What is the actual project? Also I'd say this is very basic, homework level stuff (not to be insulting but to say that an inverted index is probably overkill and brute force (no hashes or anything, just the structure you have) is likely best) so probably you are not going to be able to use a database or a module. And you don't need to for this.

So don't worry about speed. If you can build a structure you can certainly take it apart. Make one subroutine for writing to the structure even if it is just a one liner, and another for reading from it, then treat them as black boxes (after testing them) and your main loop is very short. The best way to stay sane is to break up the problem into small pieces.


In reply to Re: searching array of arrays by mattr
in thread searching array of arrays by husani

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.