in reply to Repeats exclusion

use warnings; use strict; open(my $COORD, "<", "coordinate.txt") or die("Couldn't read coordinate file - $!"); open(my $DIST, "<", "dist.txt") or die("Couldn't read distance file - $!"); my %coord; until (eof $COORD) { my $c = (split " ", scalar <$COORD>)[0]; my $d = (split " ", scalar <$DIST>)[0]; my $p = $coord{$c}; $coord{$c} = $d if !defined($p) || $d < $p; } close($COORD); close($DIST); print "$_\t$coord{$_}\n" for sort { $a <=> $b } keys %coord;

Update: Better handling of data using split.

Replies are listed 'Best First'.
Re^2: Repeats exclusion
by Grig (Novice) on Sep 12, 2010 at 11:22 UTC

    Thank you for your help!

    Sorry, but your script is excluding only the second repeat, so the actual output looks like this:

    567 344 1345 567 2346 78 3456 67 3456 789 4678 45 5349 6 6700 50 8964 560
    Thank you once more.
      You may have trailing spaces in the coordinate file. I've updated the code to be more robust in this regard.