in reply to Keeping a count of matches in a hash that satisfy more than 1 condition

that sounds like a job for... grep! (now this is untested, but i think i got everything right...)
$menucount = scalar(grep {($file{$_}{FILETYPE} eq "Menu") && ($file{$_}{VOICEOVER} eq "No") } keys %file);
sound good?
  • Comment on Re: Keeping a count of matches in a hash that satisfy more than 1 condition
  • Download Code

Replies are listed 'Best First'.
(jjhorner) Keeping a count of matches in a hash that satisfy more than 1 condition
by jjhorner (Hermit) on Jul 19, 2000 at 17:44 UTC

    I believe the asker wants to come out of this with 6 new counts, so you would have to use 4 greps, and a couple of subtractions to get all of the counts needed.

    J. J. Horner
    Linux, Perl, Apache, Stronghold, Unix
    jhorner@knoxlug.org http://www.knoxlug.org/
    
      very true... i didn't really want to type out all of the greps though! :) the question, as always, now becomes... which is faster, the foreach or the grep! anyone up for a benchmarking of the two? (my guess is the foreach will probably be quicker... but, i would be really curious to see what turns out...)