Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am not sure what modules are out there to help you. I expect there are some for formatting tables. However, here is a script that seems to produce the required output. I make another hash to associate item ids with years they occur, construct a header and sprintf template then the rest can be done in a sort of Schwartzian Transform.

use strict; use warnings; my $rhData = { 1990 => [1, 2, 3], 1991 => [2, 3, 5], 1992 => [1, 2, 7, 9], 1993 => [3, 7, 8, 13], 1994 => [1, 4, 8, 12, 17], 1995 => [2, 3, 4, 6, 7, 10, 12, 13, 14, 20], 1996 => [1, 4, 5, 8, 9, 12, 14, 16, 17, 19, 20], 1997 => [1, 2, 5, 6, 7, 10, 12, 14, 16, 17, 20], 1998 => [4, 5, 6, 7, 10, 11, 13, 14, 15, 18, 20], 1999 => [3, 5, 6, 7, 8, 9, 11, 12, 16, 19, 20] }; my $rhRevLookup = {}; foreach my $year (keys %$rhData) { $rhRevLookup->{$_}->{$year} ++ for @{$rhData->{$year}}; } my @range = (1995 .. 1999); my %frequencies = (); $frequencies{$_} ++ for map { (@{$rhData->{$_}}) } @range; my $header = q{ItemID}; $header .= qq{ $_} for @range; $header .= qq{ Freq.\n}; my $template = q{%-10d}; $template .= q{%-8s} for @range; $template .= qq{%-5d\n}; print $header; print map { sprintf $template, @$_ } map { my $raRow = []; push @$raRow, $_->[0]; foreach my $year (@range) { push @$raRow, $rhRevLookup->{$_->[0]}->{$year} ? q{=} : q{ }; } push @$raRow, $_->[1]; $raRow; } sort { $b->[1] <=> $a->[1] || $a->[0] <=> $b->[0] } map { [$_, $frequencies{$_}] } keys %frequencies;

Here is the output.

ItemID 1995 1996 1997 1998 1999 Freq. 20 = = = = = 5 5 = = = = 4 6 = = = = 4 7 = = = = 4 12 = = = = 4 14 = = = = 4 4 = = = 3 10 = = = 3 16 = = = 3 1 = = 2 2 = = 2 3 = = 2 8 = = 2 9 = = 2 11 = = 2 13 = = 2 17 = = 2 19 = = 2 15 = 1 18 = 1

I hope this is of use.

Cheers,

JohnGG


In reply to Re: Windows Maximums by johngg
in thread Windows Maximums by artist

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-19 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found