in reply to Report Formatting Help

Ok, this is most definately a quick hack, but it does work. I tweaked with the formatting of the output to match the structure of what you are looking for given the format of the data you supplied. Obviously, you will need to figure out the formatting for different data. (note the extra @reps data structure is required for output formatting purposes).

#!/usr/bin/perl use strict; my ($p, $r, $v); my (%data, %products, %reps, @reps); #iterate over data and store in hash while(<DATA>) { chomp($_); ($r, $p, $v) = split(" ", $_); $data{$p}->{$r} = $v; $products{$p} = 1; $reps{$r} = 1; @reps = sort keys %reps; } # start formatting output print " " x 10; foreach (sort keys %reps) { print "$_", " " x 4; } print "\n"; #iterate over products foreach (sort keys %products) { print "$_"; # iterate over products for( my $i = 0; $i < scalar @reps; $i++) { # see if rep has that product and print if it does if( exists($data{$_}->{$reps[$i]}) ) { print " " x 3, " " x ($i * 8), " $data{$_}->{$reps[$i]}"; } } print "\n"; } exit; __DATA__ rep1 product1 2 rep1 product2 2 rep2 product3 3 rep3 product4 4 rep3 product5 5
output:
155.~/perl/tmp > ./am.pl rep1 rep2 rep3 product1 2 product2 2 product3 3 product4 4 product5 5
hope this helps,

davidj

Replies are listed 'Best First'.
Re^2: Report Formatting Help
by Anonymous Monk on Jul 15, 2004 at 01:43 UTC
    Hello again, Thank you very much for your help...it was a very good suggestion......It helped me submit a report just in time...