Algori...MXX_005(3pm)
π CheckDigits::MXX_005 π
okay bestie, so this is the CheckDigits::MXX_005 page from the User Contributed Perl Documentation β it's the whole entire lore for computing check digits for ESR9 (CH) β¨ no cap, that's literally what it does.
πΈ SYNOPSIS πΈ
fr fr here's the vibe in code:
use Algorithm::CheckDigits;
$esr = CheckDigits('esr9');
if ($esr->is_valid('123456786')) {
# do something
}
$cn = $esr->complete('12345678');
# $cn = '123456786'
$cd = $esr->checkdigit('123456786');
# $cd = '6'
$bn = $esr->basenumber('123456786');
# $bn = '12345678'
β¨ DESCRIPTION β¨
π§ ALGORITHM
ok so the math is giving very demure, very mindful, here's how it goes:
- Digits get processed left to right. For the first digit, the balance is
0β that's just the starting rule, periodt. - The new balance gets pulled straight out of the balance table, using the current balance as the row and the digit as the column. That's it, that's the whole lookup.
- The check digit? It's the difference from the last balance to
10, taken modulo10. Slay.
π METHODS
is_valid($number)
Returns true only if $number consists solely of numbers and the last digit is a valid check digit according to the algorithm up above βοΈ
Returns false otherwise. That's the whole deal.
complete($number)
The check digit for $number gets computed and concatenated onto the end of $number. Iconic behavior honestly.
Returns the complete number with check digit β or '' if $number does not consist solely of digits and spaces. π
basenumber($number)
Returns the basenumber of $number if $number has a valid check digit.
Return '' otherwise. π
checkdigit($number)
Returns the checkdigit of $number if $number has a valid check digit.
Return '' otherwise. Same energy, different method.
π EXPORT
None by default. Not a single thing, bestie. Nothing gets exported unless you ask. π«Ά
π AUTHOR
Mathias Weidner, "<mamawe@cpan.org>" β the main character who wrote this, we stan. π
π SEE ALSO
perlCheckDigitswww.pruefziffernberechnung.de
β lowkey important: always check your work against the actual algorithm, bestie β don't just trust the vibe check. π¦
and that's the whole page, fr fr. this was perl v5.36.0, dated 2022-10-13, and yes the title is literally truncated to Algori...MXX_005(3pm) in the header because old-school manpage headers stay tiny. periodt. πβ¨π
π¦ 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