Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Data Validation Tests

by hsmyers (Canon)
on Jan 29, 2003 at 19:39 UTC ( [id://231060]=note: print w/replies, xml ) Need Help??


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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://231060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2024-04-18 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found