Algori...M11_008(3pm)
β¨ CheckDigits::M11_008 π
okay bestie, so this is a little module from the Algorithm::CheckDigits family and it's literally here to compute check digits for VAT Registration Number (DK). yep. Denmark's VAT numbers. we're doing modulus math and we're doing it cutely. π
it's User Contributed Perl Documentation, so shoutout to the community, and it's a 3pm page, iykyk.
πΈ SYNOPSIS πΈ
like, here's the whole vibe in code form:
use Algorithm::CheckDigits;
$ustid = CheckDigits('ustid_dk');
if ($ustid->is_valid('13585628')) {
# do something
}
$cn = $ustid->complete('1358562');
# $cn = '13585628'
$cd = $ustid->checkdigit('13585628');
# $cd = '8'
$bn = $ustid->basenumber('13585628');
# $bn = '1358562';
see how it all flows?? chef's kiss. you load it up, you grab your 'ustid_dk' checker, and then you justβ¦ ask it things. π
π¦ DESCRIPTION π¦
ALGORITHM
okay so this is the actual math, and it's not scary, i promise. fr fr:
- Beginning left every digit is weighted with
2,7,6,5,4,3,2,1 - The weighted digits are added.
- The sum from step 2 is taken modulo
11. - The number is valid if the sum from step 3 is zero (
0).
that's it. that's the whole thing. eight digits, eight weights, add them up, mod 11, and if you land on 0 you're valid and you ate. π
METHODS
so here's what you can actually call on your checker object:
is_valid($number)β returns true only if$numberconsists solely of numbers and the sum computed according to the algorithm given above is0. returns false otherwise. (yes, both conditions. digits only. no letters, no vibes, no exceptions. π)complete($number)β returns$numberif$numberis valid according to the algorithm given above, and returns''otherwise. note that it just hands you back what you gave it when it's valid.basenumber($number)β returns$numberif$numberis valid according to the algorithm given above, and returns''otherwise. same deal, exactly as written.checkdigit($number)β returns''if$numberis valid, and returnsundefotherwise. yep, this one's a little gremlin: it's the opposite polarity of the others and it gives you''on success andundefon failure. not me side-eyeing this API design π
bestie PLEASE clock that the return conventions here are not all the same.completeandbasenumberreturn your number (or''),checkdigitreturns''(orundef), andis_validreturns a boolean. read the docs, don't assume, that's the whole lesson. π
EXPORT
None by default.
(nothing gets exported into your namespace unless you ask. very polite of it. β¨)
π AUTHOR π
Mathias Weidner, "<mamawe@cpan.org>"
π SEE ALSO π
perlCheckDigitswww.pruefziffernberechnung.de
and that's the page!! it's from perl v5.36.0, dated 2022-10-13, and it's a 3pm page from the User Contributed Perl Documentation β so go forth, validate those Danish VAT numbers, and slay. π«ΆπΈπ
π¦ 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