john.tm has asked for the wisdom of the Perl Monks concerning the following question:
I have to run a report from a csv file, i am stuck on the part where i want to keep only unique elements from column 1,if column 5 matches a certain string, displaying the count of how many duplicates there were.
I can get the count of all the names in the list with how may times thay appear but am lost on how to do a (while column1 and if column 5 = "????") bit
this is a snippet of what i have so farinput col1 col5 output james yes james 2 dave yes dave 2 mike yes mike 3 ken no ken 1 jon yes jon 4 jon no ken yes jon yes mike no james yes dave yes mike no ken no jon yes jon yes
my %seen; while (<INPUT>) { chomp; my $line = $_; my @elements = split (",", $line); my $col_name = $elements[1]; my $col_type = $elements[5]; $seen{$col_name}++; } while ( my ( $col_name, $times_seen ) = each %seen ) { my $loc_total = $times_seen ; print " $col_name\t\t: $loc_total\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: keep only unique elements in an array displaying number of duplicates
by Athanasius (Archbishop) on Aug 24, 2014 at 16:20 UTC | |
Re: keep only unique elements in an array displaying number of duplicates.
by CountZero (Bishop) on Aug 24, 2014 at 18:17 UTC | |
Re: keep only unique elements in an array displaying number of duplicates.
by Laurent_R (Canon) on Aug 24, 2014 at 20:23 UTC |
Back to
Seekers of Perl Wisdom