bgroper has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
Newbie here, so thanks for being gentle.
I'm needing a procedure to check Australian Business Numbers (aka ABN's).
The simple algorithm is described at https://abr.business.gov.au/Help/AbnFormat
I've hacked the short procedure copied below, but I suspect it could be improved.
I don't do this often, so would be really grateful for any tips and/or clues.
TIA's
sub Check_ABN { my $number = shift ; my $abn_invalid = 0 ; my $sum = 0 ; $number =~ s/\ //g ; unless (length($number) eq 11) { $abn_invalid = 1 ; return $abn_invalid ; } $sum += (substr($number,0,1)-1)*10 ; $sum += substr($number,1,1)*1 ; $sum += substr($number,2,1)*3 ; $sum += substr($number,3,1)*5 ; $sum += substr($number,4,1)*7 ; $sum += substr($number,5,1)*9 ; $sum += substr($number,6,1)*11 ; $sum += substr($number,7,1)*13 ; $sum += substr($number,8,1)*15 ; $sum += substr($number,9,1)*17 ; $sum += substr($number,10,1)*19 ; if ($sum % 89 eq 0) { return $abn_invalid ; } else { $abn_error = 1 ; return $abn_invalid ; } # see https://abr.business.gov.au/Help/AbnFormat }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ABN checker
by choroba (Cardinal) on Feb 06, 2019 at 10:48 UTC | |
by bgroper (Novice) on Feb 06, 2019 at 11:23 UTC | |
by Marshall (Canon) on Feb 06, 2019 at 12:06 UTC | |
|
Re: ABN checker
by hippo (Archbishop) on Feb 06, 2019 at 11:02 UTC | |
by bgroper (Novice) on Feb 06, 2019 at 11:27 UTC | |
|
Re: ABN checker
by Marshall (Canon) on Feb 06, 2019 at 11:38 UTC | |
|
Re: ABN checker
by Don Coyote (Hermit) on Feb 07, 2019 at 17:37 UTC |