Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Windows Maximums

by johngg (Canon)
on Dec 20, 2006 at 20:16 UTC ( [id://590984]=note: print w/replies, xml ) Need Help??


in reply to Windows Maximums

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://590984]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found