in reply to keep only unique elements in an array displaying number of duplcates.
Hi john.tm,
While others have pointed out what you could do to get desired output, I think it wouldn't be out of place to also note a few things:
when you can do it once:while(<DATA>){ ... my $line = $_; ... }
while(my $line = <DATA>){ ... }
use warnings; use strict; use Data::Dumper; use List::Util qw(sum); my %seen; while (<DATA>) { chomp; $seen{$_}++; } print Dumper \%seen; my $total = 0; $total += $_ for values %seen; print $total; print sum( values %seen ); # sum from List::Util __DATA__ james dave mike ken jon jon ken jon mike james dave mike ken jon jon
|
|---|