in reply to Sorting a list and removing duplicate elements
Whenever you think about "remove duplicates" in Perl, think hashes. In this case, you probably want to have each hash entry be an array containing the numbers:
my %data; while(<>) { chomp; my ($name, $number) = $_ =~ /\A (\D+) (\d+) \z/x; push @{ $data{$name} }, $number if $name && $number; }
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
|
|---|