Algori...M11_001(3pm)
๐ CheckDigits::M11_001 โ okay bestie, let's talk check digits ๐
So this is CheckDigits::M11_001 (under the User Contributed Perl Documentation umbrella, and the manpage is literally titled Algori...M11_001(3pm) because Unix hates long names, slay). It's the module that computes check digits for ISBN, ISSN, VAT RN (PT), HKID (HK), Wagon number (BR), NHS (GB), and VAT (SL). Seven whole vibes, one algorithm. Periodt. โจ
๐ธ SYNOPSIS ๐ธ
use Algorithm::CheckDigits;
$isbn = CheckDigits('isbn');
if ($isbn->is_valid('3-88229-192-3')) {
# do something
}
$cn = $isbn->complete('3-88229-192-');
# $cn = '3-88229-192-3'
$cd = $isbn->checkdigit('3-88229-192-3');
# $cd = '3'
$bn = $isbn->basenumber('3-88229-192-3');
# $bn = '3-88229-192-'
That's it, that's the whole entrance. Pull the module in, grab the flavor you want, and let it validate / complete / slice / dice your numbers. ๐ฆ
โจ DESCRIPTION โจ
๐งฎ ALGORITHM ๐งฎ
Not me explaining this like we're doing homework together โ but it's actually cute, watch:
- The sequence of digits is processed right to left. Every digit is multiplied with their position in the sequence (i.e. the digit left to the check digit has the weight 2 then 3 etc.).
With a Hongkong ID (hkid) the leftmost char is replaced with its position in the alphabet and then multiplied with 8 (its weight).
- The sum of all products is computed. โ
- The sum of step 2 is taken modulo 11. ๐
- The checkdigit is the difference of the sum from step 3 to eleven, under the following conditions:
isbn,issn- If the difference is 10, the check digit is
'X'. - If the difference is 11, the check digit is
0.
- If the difference is 10, the check digit is
ustid_pt- If the difference is greater then 9, the check digit is
'0'.
- If the difference is greater then 9, the check digit is
hkid- If the difference is 10, the check digit is
'A'. - If the difference is 11, the check digit is
0.
- If the difference is 10, the check digit is
wagonnr_br- If the difference is 10, the check digit is
0. - If the difference is 11, the check digit is
1.
- If the difference is 10, the check digit is
nhs_gb- If the difference is 10, the number would not be taken.
- If the difference is 11, the check digit is
0.
vat_sl- This is a little bit unclear, don't trust on the method for this type. ๐ฉ
Real talk for a sec: that vat_sl line is a genuine "idk bestie" from the original. The docs literally say this one is a little bit unclear and you shouldn't trust the method for this type. Don't build anything mission-critical on it, mkay? ๐
๐ซถ METHODS ๐ซถ
is_valid($number)โ Returns true only if$numberconsists solely of numbers 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 and spaces.
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. Zero, zilch, nada. You want stuff? Import it yourself, bestie. ๐
๐ AUTHOR ๐
Mathias Weidner, <mamawe@cpan.org> โ absolute icon, wrote the whole thing. ๐
๐ฅ SEE ALSO ๐ฅ
perl, CheckDigits, www.pruefziffernberechnung.de.
Okay that's the whole page, you ate that. No cap. ๐ This little beauty is perl v5.36.0, dated 2022-10-13 โ and the manpage header/footer knows it as Algori...M11_001(3pm) from the User Contributed Perl Documentation collection. Go forth and validate those digits, main character. ๐๐โจ
๐ฆ 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