in reply to counting occurrence of an element in a hash
It's actually easier than you're making it:
use warnings; use strict; use Data::Dumper; my %hash = ( 'ScreenName1.Description1' => { 'ScreenName' => 'A', 'Description' => 'A Description of this button', 'Type' => 'On/Off' }, 'ScreenName2.Description2' => { 'ScreenName' => 'B', 'Description' => 'A Description of this button', 'Type' => 'Momentary' }, 'ScreenName3.Description3' => { 'ScreenName' => 'A', 'Description' => 'A Description of this button', 'Type' => 'Momentary' }, 'ScreenName4.Description4' => { 'ScreenName' => 'A', 'Description' => 'A Description of this button', 'Type' => 'On/Off' }, 'ScreenName5.Description5' => { 'ScreenName' => 'B', 'Description' => 'A Description of this button', 'Type' => 'On/Off' }, ); my %ScreenNameCount; $ScreenNameCount{$hash{$_}{ScreenName}}++ foreach keys %hash; print Dumper \%ScreenNameCount;
This outputs:
$VAR1 = { 'A' => 3, 'B' => 2 };
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: counting occurrence of an element in a hash
by JusaEngineer (Novice) on Jun 05, 2021 at 19:04 UTC |