#!/usr/local/bin/perl # # isbncheck: ISBN validation checker. # # [1996/09/18] OSHIRO Naoki. # # $Log:$ # # Reference: 「C 言語による最新アルゴリズム事典」奥村,技術評論社,1991. while (<>) { next unless (/ISBN([-\dX]+)\b/i); @isbn=split('', $1); $remain=$'; @tmp=(); foreach $n (@isbn) { next if ($n eq '-'); $n='10' if ($n eq 'X'); push(@tmp, $n); } if (&check(@tmp)) { # print "Valid:\n"; } else { print "False:$_"; } $_=$remain; redo; } sub check { local(@isbn)=@_; local($i); for ($i=0; $i<$#isbn; $i++) { $isbn[$i+1]+=$isbn[$i]; } for ($i=0; $i<$#isbn; $i++) { $isbn[$i+1]+=$isbn[$i]; } return (($isbn[$#isbn]%11)==0); } # major-mode: perl