Fellow Monks.
I have a created hash key and want to count the number of each names present. I have already created the hash. The problem I am having is extracting the counts.
Example Data
AAA
AAA
ABC
ACC
ACB
Below is my code.
my %name; open(FILE, $ARGV[0]) or die "Cannot open the file: $!"; my $hashkey; my $hashvalue; while (my $line = <FILE>) { if ($line =~ /(\S+)/) { $hashkey = $1; $hashvalue = $line; $name{$hashkey} = $hashvalue; $name{$hashkey}++; } elsif ($line =~ /\S/) { chomp $line; } } foreach my $hashname (keys %name) { print "$_ $name{$_}\n" for keys %name; } close FILE; exit;
pseudo code
if $hashname exists
count{}++
Desired Output
AAA 2
ABC 1
ACC 1
ACB 1
In reply to Obtaining number of counts per each name in hash by gghelpneeded
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |