What you tried to do (and failed) is to calculate the minimum and maximum number of occurrences.
foreach $word (%tag) {
$maxTagCnt = $tag{word} if $tag{word} lt $maxTagCnt;
$minTagCnt = $tag{word} if $tag{word} gt $minTagCnt;
}
There are two mistakes here. The first is that you iterate over all elements of %tag, not just the keys. Use foreach $word (keys %tag) {...} instead, or use each. The second mistake is that you try to compare numbers with lt and gt. Those two compare strings, but "2" gt "10" isn't what you want. Use < and > instead.
You can make that even easier:
use List::Util qw(min max);
my $maxTagCount = max values %tag;
my $minTagCount = min values %tag;
|