#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my $commandline=shift;
my $commandline2=shift;
my $commandline3=shift;

print "Adds up total strings of each value in column $commandline2, from tab-separated CSV $commandline \n";

if(!defined($commandline)){
	print "No CSV specified from which to read!\n";
}

if(!defined($commandline2)){
	print "No column specified! \n";
}

my @currenttags;
my $tag;
my %valuehash=();

open (FPOINTER,$commandline);
while ($tag= <FPOINTER>) {
	chomp $tag;
	my @tagarray=split('\t',$tag);
	push @currenttags, $tagarray[$commandline2];
}
close (FPOINTER);

my $count=0;

foreach $tag (@currenttags) {
	$count++;
	if(!$valuehash{$tag}){
			$valuehash{$tag}=1;
		} else {
			$valuehash{$tag}++;
		}
		

}

my $k;
my $check=0;
foreach $k (keys (%valuehash)){
	print " $k $valuehash{$k} \n";
	$check=$check+$valuehash{$k};
}
print " Total: $count \n";

exit;
