in reply to Re^2: Sorting a list and removing duplicate elements
in thread Sorting a list and removing duplicate elements
Change ${data}{$name} to be a hash instead of an array.
#!/usr/bin/perl use strict; use warnings; my %data; while (<DATA>) { chomp; next unless /\S/; my ($name, $num) = /(.*)\s+(\d+)/; $data{$name}{$num} = 1; } foreach my $name (sort keys %data) { print "$name "; print join ',', sort { $a <=> $b } keys %{$data{$name}}; print "\n\n"; } __END__ Chee S. L. 8 Cheng T. H. 5 Cheng T. H. 2 Chetan M. 4 Cheng T. H. 2
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|