#!/usr/bin/perl
# By Andrew McCarthy (andrewmc@netsoc.ucd.ie)
# This program is provided "as is" without any warranty of any kind.
# "If it blows up, don't blame me".
# Feedback welcome.
#
# This script takes a file of the format "lookuptime ip hostname", and
# removes any repeated entries for each ip. The entry output is that
# with the most recent (highest) lookuptime. The output is unsorted.
while(<>){
        chomp;
        ($time,$ip,$name)=split;
        if (exists $h{$ip}) {
                ($oldtime,$oldname)=split(' ',$h{$ip});
                if ($oldtime<$time) { $h{$ip}="$time $name"; }
        }
        else { $h{$ip}="$time $name"; }
}
while(($ip,$temp)=each(%h)){
        ($time,$name)=split(' ',$temp);
        print "$time $ip $name\n";
}
