#!/usr/bin/perl -w
use strict;

my $id = $ARGV[0] || <>;
$id =~ s/[^\d\.]//go;
my @id=split(//,$id);
@id=(@id,'.') if (@id == 8);
if (@id != 9) {
  die "Not enough digits!\n";
}
my $dot;
my $res;
my $f=1;
for my $d (@id) {
  if ($d eq '.') {
    die "Too many missing digits\n" if ($dot);
    $dot=$f;
  } else {
    $res.=($d*$f);
  }
  $f=3-$f;
}
my $sum;
my @res=split(//,$res);
for my $r (@res) {
  $sum+=$r;
}
if ($dot) {
  my $digit=10-($sum%10);
  $digit += 9 if (($digit&1) && ($dot == 2));
  $digit /= $dot;
  $digit=0 if ($digit eq 10);
  print "Missing digit is $digit\n";
} else {
  print "Checksum is ",($sum%10?'invalid':'valid'),"\n";
}
