in reply to ABN checker
There's no need to backslash a space in regular expressions. Moreover, there's no need for a substitution in this case, transliteration does the same job (and is simpler and faster).
There's a pattern in the computation of the sum which could be expressed by a for loop.
See my version below:
sub check_abn { my ($number) = @_; $number =~ tr/ //d; return if 11 != length $number; my $sum = 0; $sum += (2 * $_ - 1) * substr $number, $_, 1 for 1 .. 10; $sum += 10 * (substr($number, 0, 1) - 1); return $sum % 89 == 0 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: ABN checker
by bgroper (Novice) on Feb 06, 2019 at 11:23 UTC | |
by Marshall (Canon) on Feb 06, 2019 at 12:06 UTC |