Something like:
use strict; use warnings; my %hash = (); for (<DATA>) { chomp; my ($day, $ip, $i, $j) = split(q{,}, $_); $hash{$day}{$ip}{i} += $i; $hash{$day}{$ip}{j} += $j; } foreach my $day (sort keys %hash) { foreach my $ip (sort keys %{$hash{$day}}) { print qq{$day,$ip,} . $hash{$day}{$ip}{i} . q{,}. $hash{$day}{$ip}{j}; } } __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
$ perl -l 637112.pl 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,1 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,3 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
Update: Renamed variables from $a, $b to $i, $j as adviced by GrandFather.
--
Andreas

In reply to Re: Array question by andreas1234567
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.