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.


In reply to Contextual/categorical Histogram by f77coder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.