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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.