Algori...M10_004(3pm)
๐ CheckDigits::M10_004 โ the manual, but make it cute โจ
okay so bestie, welcome to Algori...M10_004 โ yep that's the truncated header, it's section 3pm (User Contributed Perl Documentation), and it lives in the Algorithm::CheckDigits family. She computes check digits! For 2aus5, EAN, ILN, ISBN13, and NVE. Multiple gigs, one module, we love a versatile queen ๐
โจ SYNOPSIS โจ
the whole vibe in one go:
use Algorithm::CheckDigits;
$ean = CheckDigits('ean');
if ($ean->is_valid('7622200004607')) {
# do something
}
$cn = $ean->complete('762220000460');
# $cn = '7622200004607'
$cd = $ean->checkdigit('7622200004607');
# $cd = '7'
$bn = $ean->basenumber('7622200004607');
# $bn = '762220000460'
likeโฆ it just works ๐
๐ธ DESCRIPTION ๐ธ
๐งฎ ALGORITHM
okay pay attention because this is the whole personality of the module:
- Beginning right, all numbers are weighted alternatively
1and3(that is, the check digit is weighted1). so likeโฆ from the right: 1, 3, 1, 3, no cap ๐ - The sum of all products is computed.
- The sum of step 3 ist taken modulo 10. (yes bestie, the page literally says "step 3" here โ we are not editing the original, we are respecting her ๐ญ)
- The check digit is the difference between
10and the number from step 3.
To validate: the total of the digits of all numbers inclusive check digit taken modulo 10 must be 0. that's it, that's the vibe check โ
๐ ๏ธ METHODS
is_valid($number)โ Returns true only if$numberconsists solely of digits, spaces and hyphen and the last digit is a valid check digit according to the algorithm given above.
Returns false otherwise,
complete($number)โ The check digit for$numberis computed and concatenated to the end of$number.
Returns the complete number with check digit or '' if $number does not consist solely of digits, spaces and hyphen.
basenumber($number)โ Returns the basenumber of$numberif$numberhas a valid check digit.
Return '' otherwise.
checkdigit($number)โ Returns the checkdigit of$numberif$numberhas a valid check digit.
Return '' otherwise.
๐ฆ EXPORT
None by default. she's lowkey private like that ๐
๐ BUGS AND LIMITATIONS ๐
When invoked as "CheckDigits('isbn13')" the module checks whether the first three digits (the country code) are 978 or 979 โ the current (as of 2006) EAN country codes for books. If at any time other EAN country codes for ISBN-13 will be specified and the then responsible maintainer ignores this in the code, please send a friendly email. friendly!!! we are being friendly about it, that's the rule ๐ซถ
๐ AUTHOR ๐
Mathias Weidner, "<mamawe@cpan.org>"
๐ฆ SEE ALSO ๐ฆ
perl, CheckDigits, www.pruefziffernberechnung.de.
and that's the whole page, bestie โ no notes, she ate ๐
sign-off time: this beautiful thing is perl v5.36.0, dated 2022-10-13, and it's the Algori...M10_004(3pm) page ๐ stay valid, stay checkdigited, mwah ๐โจ
๐ฆ where this page comes from
- ubuntu noble: libalgorithm-checkdigits-perl 1.3.6-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libalgorithm-checkdigits-perl 1.3.6-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libalgorithm-checkdigits-perl 1.3.6-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms