in reply to optimize percentile counting in hash
You need to wrap your code in <code> and </code> tags. The characters [ and ] are special to perl monks and can't put put as literal text in your post. You should also use <p> and </p> tags around paragraphs.
A general tip is to put
at the start of every script you write until you know what you are doing. They wil pick up typos and dubious practices.use strict; use warnings;
Assuming I've understood your problem then this does what you want.
Now %count will have a key/value for each datum and its frequency as a percentage.my @data = get_data(); # or however you get them my %count; foreach my $datum (@data) { ++$count{$datum}; }; foreach my $item_count ( values %count ) { $item_count *= 100/@data; }
In Section
Seekers of Perl Wisdom