Hello,
I have some very large hash tables and I need to get all the tables which fit certain conditions. I am looking for an easy and fast way to do this. I know in SQL this could be easily done but I am not sure if for hash table this would apply.
Below you have a sample : The hast table can be divided into 6 sections (L1-L6). I want to create a new hash tables which only would contain sections from where several conditions have been fullfilled. For example :
- The side has to be the same
- The CPN has to be the same
- The number of states and the state number has to be the same.
You will see that the new result will have only 4 sections. For two sections the conditions were fullfilled. Does anybody have an idea to query for several conditions in a big hash table fast and easy. I put in a sample piece of a hast table

Source hash table : 001 => HASH(0x1e19710) 'CPN' => 'A1' 'REFDES' => 'L1' 'SIDE' => 'top' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 STATE3 => HASH(0x1e19758) 'STATECPN' => 43124388023 002 => HASH(0x1e19710) 'CPN' => 'A1' 'REFDES' => 'L2' 'SIDE' => 'top' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 003 => HASH(0x1e19710) 'CPN' => 'A1' 'REFDES' => 'L3' 'SIDE' => 'top' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 STATE3 => HASH(0x1e19758) 'STATECPN' => 43124388023 004 => HASH(0x1e19710) 'CPN' => 'A2' 'REFDES' => 'L4' 'SIDE' => 'top' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 STATE3 => HASH(0x1e19758) 'STATECPN' => 43124388023 005 => HASH(0x1e19710) 'CPN' => 'A1' 'REFDES' => 'L5' 'SIDE' => 'bottom' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 STATE3 => HASH(0x1e19758) 'STATECPN' => 43124388023 006 => HASH(0x1e19710) 'CPN' => 'A1' 'REFDES' => 'L6' 'SIDE' => 'top' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 Result should be something like this : top => HASH(0x1e19710) 001 => HASH(0x1e19710) 'CPN' => 'A1' 'REFDES' => ARRAY(0x1d15ef0) 0 'L6' 1 'L2' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 002 => HASH(0x1e19710) 'CPN' => 'A1' 'REFDES' => ARRAY(0x1d15ef0) 0 'L1' 1 'L3' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 STATE3 => HASH(0x1e19758) 'STATECPN' => 43124388023 003 => HASH(0x1e19710) 'CPN' => 'A2' 'REFDES' => ARRAY(0x1d15ef0) 0 'L4' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 STATE3 => HASH(0x1e19758) 'STATECPN' => 43124388023 bottom => HASH(0x1e19710) 001 => HASH(0x1e19710) 'CPN' => 'A1' 'REFDES' => ARRAY(0x1d15ef0) 0 'L5' 'SIDE' => 'bottom' 'STATES' => HASH(0x1e19740) STATE1 => HASH(0x1e19758) 'STATECPN' => 43124388002 STATE2 => HASH(0x1e19758) 'STATECPN' => 43124388003 STATE3 => HASH(0x1e19758) 'STATECPN' => 43124388023

In reply to Optimizing quickly hash tables by checking multiple conditions by juo

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.