#! /usr/bin/env perl # $Id: hostnumber.pl 2666 2009-01-16 01:01:27Z jnieuwen $ # $URL: svn+ssh://shell.jeroen.se./usr/home/jnieuwen/subversion/files/trunk/h/hostnum/hostnumber.pl $ # $Author: jnieuwen $ # $Date: 2009-01-16 02:01:27 +0100 (Fri, 16 Jan 2009) $ # $Rev: 2666 $ use strict ; use warnings ; my $input = reverse $ARGV[0] ; my $total = 0 ; my $len = $ARGV[1] ; my $number = $ARGV[0] ; my $count = 2 ; if (length($input) != $len) { print "$input does not have length $len\n" ; exit 1 ; } while ($input) { $total += $count++ * chop($input) ; } #print $total."\n" ; #print $total % 11 ."\n" ; my $checksum = 11 - ($total % 11) ; $checksum = '0' if ($checksum == 11) ; $checksum = 'X' if ($checksum == 10) ; print "$checksum"."$number\n" ;