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