[~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