f77coder has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I would like to create a contextual/categorical histogram. I've looked at Histogram and others but them see to be only numeric.
I'm thinking here's the pseudo code but I'm getting confused on keys, hashes and arrays.
My input is grabbing line by line from a file, there are M columns
1. split the line into my @array=split @colref ?
2. shove results from 1 into a hash? my %hash= @array?
3. count duplicate items ? $counts{$_}++ for @my_array;
4. add counts to keys in hash? ;
5. get next line
6 check if key exists?
7 if key exists, increment count
else add new key
next line
example array
use Data::Dumper; $Data::Dumper::Sortkeys=1; my @my_array=('a','-2','3','b','0xffff','c','2','b','a','4','a','a','2 +00'); my %counts; $counts{$_}++ for @my_array; print Dumper(\%counts);
$VAR1 = { '-2' => 1, '0xffff' => 1, '2' => 1, '200' => 1, '3' => 1, '4' => 1, 'a' => 4, 'b' => 2, 'c' => 1 };
Many thanks for any help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Contextual/categorical Histogram
by Athanasius (Archbishop) on Aug 03, 2014 at 04:24 UTC | |
by f77coder (Beadle) on Aug 03, 2014 at 18:35 UTC | |
by Athanasius (Archbishop) on Aug 04, 2014 at 04:22 UTC |