in reply to Data Validation Tests

Given the amount of time I hang-out in book space, I would have liked to see something along these lines for ISBN numbers. When last I checked CPAN there was at least one solution (more actually) but most required something along the lines of use Kitchen::Sink; so after a bit of looking around I came up with:

sub checkISBN { my @digits = split(//,uc(shift)); my $n = scalar(@digits); my $sum = 0; my $m = 10; my $cd; if ($n != 10) { return (0,($n < 10 ? '-' : '+')); } else { for (0..@digits - 2) { $sum += $digits[$_] * $m--; } $cd = qw(0 X 9 8 7 6 5 4 3 2 1)[$sum % 11]; return ($cd eq $digits[-1],$cd); } }
Don't know if this is what you had in mind, but I found it useful...

--hsm

"Never try to teach a pig to sing...it wastes your time and it annoys the pig."

Replies are listed 'Best First'.
Re: Re: Data Validation Tests
by Flame (Deacon) on Jan 29, 2003 at 22:35 UTC
    Hmm, ISBN. Sounds reasonable. Thanks for the suggestion, and the sample. I'll see if I can work it into the plan.



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)