Algori...M11_015(3pm)
๐ NAME ๐
CheckDigits::M11_015 โ bestie, this is the module that computes check digits for ESR5 (CH), aka the Swiss payment slip thing, and it's lowkey iconic ๐
It ships as part of Algorithm::CheckDigits, so like, that's the family it lives in ๐ซถ
โจ SYNOPSIS โจ
okay so first you gotta summon it:
use Algorithm::CheckDigits;
$ustid = CheckDigits('esr5_ch');
if ($ustid->is_valid('050001000012000 241170032660178 10304')) {
# do something
}
$cn = $ustid->complete('0001000012000 241170032660178 10304');
# $cn = '050001000012000 241170032660178 10304'
$cd = $ustid->checkdigit('0001000012000 241170032660178 10304');
# $cd = '05'
$bn = $ustid->basenumber('050001000012000 241170032660178 10304');
# $bn = '0001000012000 241170032660178 10304';
see how the 'esr5_ch' handle gets you your very own $ustid object? and then it just... does the math for you? main character energy fr fr ๐
๐ธ DESCRIPTION ๐ธ
๐งฎ ALGORITHM
the math is giving โจchecksum realnessโจ and honestly it's not even hard, watch:
- starting from the right, every digit gets weighted with the repeating sequence
2, 3, 4, 5, 6, 7โ and yes bestie it repeats,2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, ...forever and ever ๐ซ - add all those weighted digits together ๐ง
- take that sum from step 2 and hit it with
modulo 11๐ฅ - the checkdigit is
11minus the sum from step 3. BUT โ and this is the plot twist โ if that difference comes out to11, then the checkdigit is00๐ญ periodt.
โ ๏ธ warning bestie: step 4 is not a typo. when the difference is11, you write00. don't come for me, that's just what the spec says ๐
๐ ๏ธ METHODS
is_valid($number)โ gives you back true only if$numberis made up solely of numbers (spaces between them are fine, she's flexible like that ๐ ) and the first two digits are valid check digits per the algorithm above. anything else? false. no cap. ๐complete($number)โ computes the check digit for$numberand inserts it before the number ๐. she hands you back the complete number with its check digit, or''if$numberisn't made up solely of digits and spaces ๐basenumber($number)โ if$numberhas a valid check digit, you get the basenumber back ๐. otherwise?''. that's it. that's the vibe. ๐checkdigit($number)โ if$numberhas valid check digits, she returns them ๐ฆ. otherwise''. no notes.
๐ฆ EXPORT
None by default. literally nothing gets exported, she's lowkey mysterious like that ๐ง
๐ AUTHOR ๐
Mathias Weidner, "<mamawe@cpan.org>" โ the icon, the legend, the moment ๐
๐ SEE ALSO ๐
perlCheckDigitshttp://www.pruefziffernberechnung.de/E/Einzahlungsschein-CH.shtml(german ๐ฉ๐ช)http://www.sic.ch/de/dl_tkicch_dta.pdf, page 52 (german ๐ฉ๐ช)
and that's the whole page bestie!! this one was documented for perl v5.36.0 and dated 2022-10-13, so if that's not your perl era, just keep it in mind ๐ slay, go validate some Swiss payment slips, 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