I am looking at a possible "time/space" trade-off problem. I am evaluating storing a set of data that is keyed by 3 attributes:

attr1 is a number in the range 200-35000
attr2 is a string, 6-9 characters
attr3 is a string of 10 characters

The hash key is "attr1.attr2.attr3", The hash content is a ref to an anon array.

Could there be a significant performance improvement by maintaining a second hash of just 'attr1' to pre-determine if any keys start with attr1?

my $arrayRef; if ( defined ?attr1Hash{$attr1}){ my $key ="attr1.attr2.attr3"; $arrayRef = $fullHash{$key}; } if ( defined $arrayRef){ ... }
vs
my $arrayRef; my $key ="attr1.attr2.attr3"; $arrayRef = $fullHash{$key}; if ( defined $arrayRef){ ... }
UPDATE:

I have a process that is watching (ala 'less') the system syslog file for pre-determined message keywords, which are reported across the net to a higher authority. Some of the tests done on a record may cause sub-shells to be spawned to determine system state.
But basicly pretty straight forward.

Enhancement creep:

Generate a special event report if any unique process(pid), in a specified time period, creates more than 3 of the syslog messages. I have gone from statless scan to a time limited historic context.

The module I am working on holds the 'state'

$EventHash{$pid} = [ create_ts, last_upt, $ev_cnt];

It is always better to have seen your target for yourself, rather than depend upon someone else's description.


In reply to Hash space/ time tradeoff by Wiggins

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.