Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Keeping a count of matches in a hash that satisfy more than 1 condition

by barndoor (Pilgrim)
on Jul 19, 2000 at 19:32 UTC ( #23206=note: print w/replies, xml ) Need Help??


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

If you stick the count variables in a hash you can reduce the loop code a bit. Not sure if this is any faster or more efficient. You have to define the count structure up front as well.
my $count = { "Menu" => { "Count" => 0, "Voice" => 0, "NoVoice" => 0}, "Video" => { "Count" => 0, "Voice" => 0, "NoVoice" => 0} }; foreach my $entry (values(%$file)) { $count->{$entry->{FILETYPE}}->{"Count"}++; if($entry->{VOICEOVER} eq "No") { $count->{$entry->{FILETYPE}}->{"NoVoice"}++ } else { $count->{$entry->{FILETYPE}}->{"Voice"}++ } } # Example getting one of the counts out. print $count->{"Menu"}->{"Count"} . "\n";
When I started this I thought it would come out smaller than this. Thought someone might find it useful or make it a bit smaller.
  • Comment on Re: Keeping a count of matches in a hash that satisfy more than 1 condition
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://23206]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-04-01 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (186 votes). Check out past polls.

    Notices?