Algori...M11_011(3pm)

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

✨ Algori...M11_011 πŸ’… (that's the 3pm perl manual page, bestie)

okay so this whole page lives in the User Contributed Perl Documentation section of the perl man pages, and honestly? it's giving "weird little Dutch tax number math" and I'm obsessed. let's get into it 🫢


πŸ’– NAME πŸ’–

CheckDigits::M11_011 β€” bestie, this module computes check digits for the VAT Registration Number, aka the one from the NL (Netherlands). 🧚


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the whole vibe, no notes:

use Algorithm::CheckDigits;

$ustid = CheckDigits('ustid_nl');

if ($ustid->is_valid('123456782')) {
      # do something
}
if ($ustid->is_valid('123456782B04')) {
      # do something
}

$cn = $ustid->complete('12345678');
# $cn = '123456782'
$cn = $ustid->complete('12345678.B04');
# $cn = '123456782B04'

$cd = $ustid->checkdigit('123456782');
# $cd = '2'
$cd = $ustid->checkdigit('123456782B04');
# $cd = '2'

$bn = $ustid->basenumber('123456782');
# $bn = '12345678';
$bn = $ustid->basenumber('123456782B04');
# $bn = '12345678.B04';

like… look at her go ✨ every value is right there, character for character, don't touch them.


🌸 DESCRIPTION 🌸

okay so this VATRN? it has 12 "digits" β€” except not all of them are digits, which is the plot twist 😭

  • the third last one has to be a B πŸ’€
  • the fourth last one is the checkdigit πŸ‘‘
  • and the last two digits? no idea what they mean, and I'm not gonna pretend. genuinely, the author says "I don't know anything about the meaning of the last two digits." and honestly? same energy, we respect the honesty πŸ’…

you can compute the checkdigit with this module using the whole VATRN, or literally just the first eight digits. your call, bestie πŸ“

πŸŽ€ ALGORITHM πŸŽ€

the math is lowkey simple and highkey iconic, here's the whole ritual:

  1. Beginning right with the digit before the checkdigit, all digits are weighted with their position. I.e. the digit before the checkdigit is multiplied with 2, the next with 3 and so on. πŸ”₯
  2. The weighted digits are added. βž•
  3. The sum from step 2 is taken modulo 11. πŸŒ€
  4. If the sum from step 3 is 10, the number is discarded. πŸ’€ (yes, that's a hard no, bestie β€” no check digit for you)

πŸ‘‘ METHODS πŸ‘‘

four methods, all main character energy, let's go:

  • is_valid($number) β€” returns true only if the first eight positions of $number consist solely of digits (maybe followed by 'B' and to further digits) and the eighth digit is a valid check digit according to the algorithm given above. ✨

Returns false otherwise. πŸ’”

  • complete($number) β€” the check digit for $number is computed and inserted at position eight of $number. πŸŽ€

Returns the complete number with check digit, or '' if $number does not consist solely of digits a dot and maybe 'B' at the ninth position. πŸ™ˆ

  • basenumber($number) β€” Returns the basenumber of $number if $number has a valid check digit. πŸ’–

Return '' otherwise. 😭

  • checkdigit($number) β€” Returns the check digits of $number if $number has valid check digits. ⭐

Return '' otherwise. πŸ¦‹

🌈 EXPORT 🌈

None by default. not a single thing, we keep it minimal periodt πŸ’…


πŸ”₯ SEE ALSO πŸ”₯

go read these too, iykyk:

  • perl, CheckDigits, www.pruefziffernberechnung.de,

πŸ’œ AUTHOR πŸ’œ

Mathias Weidner, "<mamawe@cpan.org>" β€” thank you for your service, king πŸ‘‘


Copyright 2004-2020 by Mathias Weidner

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

real talk bestie, that means it's free software under the same terms as Perl itself β€” respect the license, always 🫢

okay that's the whole page, you ate it, no crumbs πŸ’… this was perl v5.36.0, dated 2022-10-13, from the Algori...M11_011(3pm) file β€” mwah, go compute some Dutch VAT numbers, love u, bye! πŸŒΈπŸŽ€βœ¨

πŸ“¦ where this page comes from