Perl Calc Sum Rows

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Perl Calc Sum Rows as PDF for free.

More details

  • Words: 149
  • Pages: 2
[~vishnu]# cat test1.pl #!/usr/local/bin/perl use strict;

my %users = (); my %books = (); my %grade = ();

my $id_col = 0; my $bookname_col = 1; my $grade_col = 2; my $user_col = 3;

my @ids = ();

open (FH, "<", "test.csv") or die "Can't open test.csv for reading: $!\n"; while () { my @F = split /\t/, $_; my $id = $F[$id_col]; if (! exists $users{$id}) { push @ids, $id ; } $users{$id} += $F[$user_col]; $books{$id} = $F[$bookname_col]; $grade{$id} = $F[$grade_col];

} close (FH); my $id;

foreach $id (@ids) { print "$id\t$books{$id}\t$grade{$id}\t$users{$id}\t\n" ; }

[~vishnu]# cat test.csv 123

linux A

200

345

unix B

300

245

solaris C

400

123

linux A

250

456

aix

D

100

345

unix B

300

245

solaris C

250

123

linux A

150

[~vishnu]# ./test1.pl 123

linux A

600

345

unix B

600

245

solaris C

650

456

aix

[~vishnu]#

D

100

Related Documents

Perl Calc Sum Rows
December 2019 2
Perl
November 2019 27
Calc
November 2019 35
Calc
May 2020 17
Perl
November 2019 29