You could stuff all your data into a Hash-of-Hashes structure, then print out based on the dates you have.
#!/usr/bin/env perl use strict; use warnings; my %data; while (<DATA>) { next if /ZIP/; chomp; my ($zip, $money, $date, $id) = split /\s*,\s*/; $data{$zip}{total} += $money; $data{$zip}{date} = $date; $data{$zip}{id} = $id; } my @dates; for my $zip (keys %data) { push @dates, $data{$zip}{date} if exists $data{$zip}{date}; } print "ZIP"; for (@dates) {print ",Total($_)"} print ",ID\n"; for my $zip (keys %data) { print "$zip, "; for (@dates) { if ($data{$zip}{date} eq $_) { print "$data{$zip}{total},"; } else { print "0,"; } } print "$data{$zip}{id}\n"; } __DATA__ ZIP, Money, Date, ID 12345, 200, 11062000, C1234 12345, 50, 11062000, C1234 67890, 50, 11072000, D5555

prints:

ZIP,Total(11062000),Total(11072000),ID 12345, 250,0,C1234 67890, 0,50,D5555

This matches your desired output, based on the input example.


In reply to Re: Creating One Table From Several Hashes by toolic
in thread Creating One Table From Several Hashes by bryced1234

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.