Seems like you need to construct a second hash which is indexed on the fields you want if you don't want to do this iteratively. You'd need to construct it either by iterating through your current data structure once or at the same time you build this. For example
my %oslookup; while( my ($pc,$data) = each %hoh ) { push @{ $oslookup{$data->{'os'}} }, $pc; } # later on print "linux pcs are: ", join(',', @{$oslookup{'linux'} || []}, "\n";
Similarly a second hash for the 'user' field. If you expect to have a lot of keys for each record, with a little creativity you can build a single index hash which has lookups for all the keys in your data structure. When/If this gets really big you might want to change to using a DB structure - either RDBMS or as I prefer DB_File. You'll probably want to use the B-Tree implementation to store multiple values for a key.

In reply to Re: HoH search question by stajich
in thread HoH search question by traveler

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.