Yes, you can still use the method suggested by dws (or my variant thereof) but you'll have to restructure your user hash like my  %users:
use strict; my %users = (); my %matches = (); my %search = ( sex => 'F', age => 19, st => 'FL' ); ## load users hash foreach (<DATA>) { chomp; my ($user, $sex, $age, $st) = split /\|/; $users{$user}{sex} = $sex; $users{$user}{age} = $age; $users{$user}{st} = $st; } ## Perform searches foreach my $user (keys %users) { my $match = 1; foreach my $key (keys %search) { $match = 0, last if $users{$user}{$key} ne $search{$key}; } $matches{$user}++ if $match; } ## Print out the matches (if any) foreach (keys %matches) { print "user: '", $_, "' sex: '", $users{$_}{sex}, "' age: '", $users{$_}{age}, "' st: '", $users{$_}{st}, "'\n"; } print "No matches found!\n" if not %matches; __DATA__ JOE|M|18|AL SUE|F|18|MS BOB|M|19|CA EVE|F|20|FL PAM|F|19|FL ABE|M|18|FL NAN|F|19|CA
Note that this could be very slow if you have a large number of users and/or a large number of criteria to match. Worst case is criteria count * user count iterations. I'm not the greatest at optimizing code, so no doubt there are more efficient ways to do it (TAMEWTDI).

--Jim


In reply to Re: Re: Re: Search Categories - Most efficient way by jlongino
in thread Search Categories - Most efficient way by perleager

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.