I've worked on this for more than a couple of hours now using hashes and makeing
Any reason you didn't post the code you created so we could point out which parts need improvement?

Anyway, you're gathering data in three dimensions: By month, within the month by product, within the product by country. This cries for a multi-dimensional hash.

Here's an example grabbing the input with a regular expression, setting up a hash and printing out an incomplete result, but you should be able to fill in the gaps:

my $data = join '', <DATA>; my $by_month = {}; while($data =~ /^(\d+).*?(\w+) +(\d+) +(\w+)/mg) { print "Capturing $1 $2 $3 $4\n"; $by_month->{$1}->{$2}->{$4} += $3; } for my $month (1..12) { print "Month: $month\n"; for my $product (qw(Shirts Shoes Caps)) { printf "%7s ", $product; for my $country (qw(Asia Australia UK)) { printf "%6d ", $by_month->{$month}->{$product}->{$country} || 0; } print "\n"; } } __DATA__ 1/2/04 Shirts 32 Australia 1/9/04 Shoes 234 Asia 2/12/04 Caps 109 UK 4/4/04 Shoes 6 Asia 4/4/04 Shirts 12 Australia 5/6/04 Shirts 398 Australia
which prints out the following:
Month: 1 Shirts 0 32 0 Shoes 234 0 0 Caps 0 0 0 Month: 2 Shirts 0 0 0 Shoes 0 0 0 Caps 0 0 109 Month: 3 Shirts 0 0 0 Shoes 0 0 0 Caps 0 0 0 Month: 4 Shirts 0 12 0 Shoes 6 0 0 Caps 0 0 0

In reply to Re: (Complex)Data Manipulation by saintmike
in thread (Complex)Data Manipulation by rupesh

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.