Algori...M11_002(3pm)

πŸ“¦
version 1.3.6 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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:

  1. 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 πŸ’…).
  2. Add up all of those products. Sum time.
  3. The checkdigit is that sum from step 2 taken modulo 11.
  4. If the checkdigit comes out as '10', then the whole number is not accepted as a PZN. Sorry bestie, 10 is not it 😭.

πŸ’… METHODS πŸ’…

  • is_valid($number) β€” gives you back true only when $number is 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 $number and sticks it right onto the end. You get the full number back with its check digit, or '' if $number isn't purely digits and spaces πŸ‘‘
  • basenumber($number) β€” hands you the basenumber of $number β€” but only if $number has a valid check digit. Otherwise you get ''. No check digit, no basenumber, periodt πŸ™ˆ.
  • checkdigit($number) β€” gives you the checkdigit of $number if $number has 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