Algori...M11_002(3pm)
π NAME π
CheckDigits::M11_002 β bestie, this is the module that computes check digits for PZN (DE) β¨ (that's the German pharmaceutical number thing, iykyk). It lives in the User Contributed Perl Documentation, manual page Algori...M11_002(3pm), section 3pm.
πΈ SYNOPSIS πΈ
use Algorithm::CheckDigits;
$pzn = CheckDigits('pzn');
if ($pzn->is_valid('4877800')) {
# do something
}
$cn = $pzn->complete('487780');
# $cn = '4877800'
$cd = $pzn->checkdigit('4877800');
# $cd = '0'
$bn = $pzn->basenumber('4877800');
# $bn = '487780'
Like, that's the whole vibe check right there π«Ά
π¦ DESCRIPTION π¦
β¨ ALGORITHM β¨
okay so the math is literally this, and it's not that deep:
- Starting from the left and beginning with the first position, every digit gets multiplied by
2,3,4,... (so first digit Γ2, next Γ3, and so on, it just keeps counting up π ). - Add up all of those products. Sum time.
- The checkdigit is that sum from step 2 taken modulo 11.
- If the checkdigit comes out as
'10', then the whole number is not accepted as a PZN. Sorry bestie,10is not it π.
π METHODS π
is_valid($number)β gives you back true only when$numberis made up of nothing but numbers and the last digit is a valid check digit per the algorithm above. Anything else? false. That's it, that's the rule π.complete($number)β computes the check digit for$numberand sticks it right onto the end. You get the full number back with its check digit, or''if$numberisn't purely digits and spaces πbasenumber($number)β hands you the basenumber of$numberβ but only if$numberhas a valid check digit. Otherwise you get''. No check digit, no basenumber, periodt π.checkdigit($number)β gives you the checkdigit of$numberif$numberhas a valid check digit. If not?''. That's the whole story β¨.
π EXPORT π
None by default. Not a single thing gets exported on its own, bestie. Zero. Nada π.
π AUTHOR π
Mathias Weidner, "<mamawe@cpan.org>" β absolute icon, wrote the whole thing π«Ά
β SEE ALSO β
perl, CheckDigits, www.pruefziffernberechnung.de.
and that's a wrap, bestie π this page is perl v5.36.0, dated 2022-10-13, and it ships as part of the User Contributed Perl Documentation β slay, go compute those check digits πΈβ¨
π¦ 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