I apologize for leaping to the worst interpretation of your post! I hope the code below helps. It will muck up the date ordering, but I've run out of time tonight to clean that up.

use strict; use warnings; use Data::Dump::Streamer; my @data = ( ['01 Jul 2007','221.6.19.196',9,19], ['01 Jul 2007','221.6.19.197',1,3], ['01 Jul 2007','221.6.19.196',12,12], ['01 Jul 2007','221.6.19.197',2,2], ['02 Jul 2007','202.119.104.22',1,1], ['02 Jul 2007','221.6.19.196',20,45], ['03 Jul 2007','202.119.104.12',1,11], ['03 Jul 2007','202.119.110.236',1,2], ['03 Jul 2007','210.29.132.9',1,2], ['03 Jul 2007','210.29.141.188',1,2], ['03 Jul 2007','221.6.19.195',3,7], ['03 Jul 2007','221.6.19.196',4,7], ['03 Jul 2007','222.192.2.213',1,0], ['03 Jul 2007','202.119.108.42',3,3], ); my %sums; $sums{$_->[0]}{a} += $_->[1], $sums{$_->[0]}{b} += $_->[2] for map {["$_->[0],$_->[1]", @{$_}[2,3]]} @data; my @result = map {[@{$_}[1, 2, 3, 4]]} sort {$a->[0] cmp $b->[0]} map {[$_, split (',', $_), @{$sums{$_}}{'a', 'b'}]} keys %sums; Dump (\@result);

Prints:

$ARRAY1 = [ [ '01 Jul 2007', '221.6.19.196', 21, 31 ], [ '01 Jul 2007', '221.6.19.197', 3, 5 ], [ '02 Jul 2007', '202.119.104.22', ( 1 ) x 2 ], [ '02 Jul 2007', '221.6.19.196', 20, 45 ], [ '03 Jul 2007', '202.119.104.12', 1, 11 ], [ '03 Jul 2007', '202.119.108.42', ( 3 ) x 2 ], [ '03 Jul 2007', '202.119.110.236', 1, 2 ], [ '03 Jul 2007', '210.29.132.9', 1, 2 ], [ '03 Jul 2007', '210.29.141.188', 1, 2 ], [ '03 Jul 2007', '221.6.19.195', 3, 7 ], [ '03 Jul 2007', '221.6.19.196', 4, 7 ], [ '03 Jul 2007', '222.192.2.213', 1, 0 ] ];

DWIM is Perl's answer to Gödel

In reply to Re^3: Array question by GrandFather
in thread Array question by udinakar

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.