G'day gowthamvels,

What you're after is a very simple exercise in using Text::CSV. Here's the guts of it:

#!/usr/bin/env perl use strict; use warnings; use Data::Dump; use Text::CSV; my $csv = Text::CSV::->new; my %result; while (my $row = $csv->getline(\*DATA)) { $result{$row->[1]}[0] += $row->[6]; $result{$row->[1]}[1] += $row->[7]; } dd \%result; __DATA__ 1234,GP,20170715,0,V,97517,24,0.6 5678,Pack,20170715,0,V,97516,88,1.8 1234,GP,20170715,0,V,97517,22,0.6 5678,Pack,20170715,0,V,97517,183,3.9 1234,PRS,20170715,0,S,97517,261,5.4 5678,PRS,20170715,0,M,97517,36,0.9

Output:

{ GP => [46, 1.2], Pack => [271, 5.7], PRS => [297, 6.3] }

Please post data between <code>...</code> tags (as already requested in responses to this and your last post). Show the data as it appears in the file: do not make records into dot points or otherwise change their original format. Also check what you post, multiple times if necessary, using the "preview" button: in this instance, you posted "col1,...,col7" but there are eight columns, not seven.

— Ken


In reply to Re: group by and sum for two columns by kcott
in thread group by and sum for two columns by gowthamvels

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.