Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://23206]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found