in reply to Repeats exclusion

My approach is to filter records while reading data.

use warnings; use strict; my $format = "%-11s %-8s\n"; open my $data, '<', 'data.txt' or die "Could not open 'data.txt': $!\n"; my %dataset; RECORD: while ( my $line = <$data> ) { chomp $line; my ( $coord, $dist ) = split ',', $line; next RECORD if exists $dataset{$coord} and $dataset{$coord} < $dist; $dataset{$coord} = $dist; } printf $format, 'coordinate', 'distance'; printf $format, $_, $dataset{$_} for sort { $a <=> $b } keys %dataset;

As Occam said: Entia non sunt multiplicanda praeter necessitatem.