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; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: optimize percentile counting in hash
by max210 (Novice) on Mar 21, 2008 at 01:36 UTC | |
by ikegami (Patriarch) on Mar 21, 2008 at 01:56 UTC | |
by Anonymous Monk on Mar 21, 2008 at 02:27 UTC | |
by ikegami (Patriarch) on Mar 21, 2008 at 02:40 UTC | |
by apl (Monsignor) on Mar 21, 2008 at 02:24 UTC | |
by max210 (Novice) on Mar 21, 2008 at 02:32 UTC | |
by Anonymous Monk on Mar 21, 2008 at 02:28 UTC |