#!/usr/bin/perl -w
use strict;
open PORT, "port outdated|";
while (<PORT>) {
    if (/(\S+)\s+(\S+) < (\S+)/) {
        my ($pkg, $old, $new)= ($1,$2,$3);
        printf("%-32s %-12s < %-12s  - %s\n", $pkg, $old, $new, calcdiff($old, $new));
    }
}
sub calcdiff {
    my @old= split /([0-9]+)/, shift;
    my @new= split /([0-9]+)/, shift;

    my @diff;
    my $found=0;
    my $i=0;
    while (!$found && $i<@old && $i<@new) {
        my $o= $old[$i];
        my $n= $new[$i];
        if ($o =~ /[0-9]/) {
            if ($o eq $n) {
                push @diff, $o;
            }
            else {
                push @diff, sprintf("%s\{+%d}", $o, $n-$o);
                $found++;
                last;
            }
        }
        else {
            if ($o eq $n) {
                push @diff, $o;
            }
            else {
                push @diff, "{$o<$n}";
            }
        }
        $i++;
    }
    while (!$found && $i<@old) {
        push @diff, "{$old[$i]<}";
        $i++;
    }
    while (!$found &&$i<@new) {
        push @diff, "{<$new[$i]}";
        $i++;
    }
    return join "", @diff;
}
