Algori...M11_003(3pm)

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

πŸ’– Algori...M11_003 πŸ’– (that's the 3pm perl section, bestie β€” User Contributed Perl Documentation vibes)

okay so. picture this: it's the GDR, you've got a PKZ number, and you need to know if its check digit is fr fr valid. that's literally this module. it's CheckDigits::M11_003, it computes check digits for PKZ (GDR), and it's giving ✨ niche-but-iconic ✨.


πŸŽ€ NAME πŸŽ€

CheckDigits::M11_003 β€” compute check digits for PKZ (GDR)

no cap, that's the whole name. short. sweet. slays.


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the whole vibe in one block, copy-paste ready:

use Algorithm::CheckDigits;

$pkz = CheckDigits('pkz');

if ($pkz->is_valid('150765400354')) {
      # do something
}

$cn = $pkz->complete('15076540035');
# $cn = '150765400354'

$cd = $pkz->checkdigit('150765400354');
# $cd = '4'

$bn = $pkz->basenumber('150765400354');
# $bn = '150765400354'

see how $cn, $cd and $bn just pop out with their little comments? that's her. that's the whole module working exactly as advertised. periodt.


🌸 DESCRIPTION 🌸

✨ ALGORITHM ✨

okay this is the math part and honestly? it eats. it's a 1-through-8 pipeline and every single step matters, so no skipping, bestie:

  1. The checkdigit is set to 0. starting from zero, humble queen.
  2. From right to left the digits are weighted (multiplied) with 2,4,8,5,10,9,7,3,6,1,2,4.
  3. The products are added.
  4. The sum of step 3 is taken modulo 11.
  5. The value of step 4 is added to a multiple (0..9) of the weight of the checkdigit (2).
  6. The sum of step 5 is taken modulo 11.
  7. The checkdigit is the multiple of the weight of the checkdigit where the value of step 6 equals 10.
  8. If there can't be reached a value of 10 in step 6, the number cannot be taken as a PKZ.
⚠️ notice step 8, bestie. if step 6 never hits 10, that number is just not a PKZ. it's not "invalid-ish", it's flat-out not one. no cap.

To validate a PKZ apply steps 2 to 4 to the complete number.

that's it! the whole validation is just steps 2–4 on the full number. lowkey elegant.


🫢 METHODS 🫢

every one of these returns a real answer, and every one of these has a sad little '' waiting for you if things go wrong. let's meet them:

  • 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 given above.

Returns false otherwise,

πŸ™ˆ yes, that trailing comma is in the original. we keep the details exactly. it's canon.
  • complete($number) β€” The check digit for $number is computed and concatenated to the end of $number.

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.


🌈 EXPORT 🌈

None by default.

yup. nothing. it's not gonna dump a single symbol into your namespace unless you ask. respectful. iconic. πŸ’…


πŸ‘‘ AUTHOR πŸ‘‘

Mathias Weidner, "<mamawe@cpan.org>"

he made this. we love him for it. 🫢


πŸ“ SEE ALSO πŸ“

  • perl
  • CheckDigits
  • www.pruefziffernberechnung.de

go read those if you wanna go deeper, iykyk.


okay bestie that's the whole page!! 🌟 one last thing for the sign-off: this doc ships with perl v5.36.0 and it's dated 2022-10-13. so it's an elder gen z. still relevant. still slaying. now go validate some PKZ numbers, you absolute main character. πŸ’œβœ¨

πŸ“¦ where this page comes from