in reply to keep only unique elements in an array displaying number of duplcates.
Your code could be more efficient, but examining %seen at the end shows you have the data you want. You just need to display it. keys %hashvariable produces a list of the keys of a hash.
foreach my $name (sort keys %seen) { printf "%-6s: %-2d\n", $name, $seen{$name}; }
Output:
dave : 2 james : 2 jon : 5 ken : 3 mike : 3
Or, slightly more 'perlish',
printf "%-6s: %-2d\n",$_, $seen{$_} for (sort keys %seen);
|
|---|