in reply to ABN checker

Hello bgroper

I thought it might be useful to construct a separate weighting array, and then apply that as part of the algorithm to the submitted ABN to check. It's a little rough but I am interested to see what the thoughts are.

#!/usr/bin/perl use v5.20; use strict; use warnings; my $Num = Prepare_Num( q'51 824 753 556' ); my $verified = check_calc($Num); if( $verified == 1){ say "Valid ABN" }else{ say "ABN check has been unsuccessful" } sub check_calc{ my $Numset = shift; my $w_oset = weighting_oset(); --$Numset->[0][0]; # -[[0],[1]] ? print_list($Numset); my $sum; for my $index( 0 .. 10 ){ $sum += $Numset->[$index][0] *= $w_oset->[$index][0]; } print_list($Numset); $sum %89 == 0; } sub Prepare_Num{ my $NumString = shift; say "arg Num: $NumString"; $NumString =~ s/[^0-9]//g; say "s Num: $NumString"; my $count = $NumString =~ tr/0-9/0-9/; say "count: $count"; $count == 11 or die "non-conforming ABN. Please check."; say "tr Num: $NumString"; my $Numset = []; while( $NumString =~ m/([0-9])/g ){ push @$Numset, [$1]; } print_list( $Numset, 1 ); return( $Numset ); } sub weighting_oset{ #my $woset = [[[0],[1]],[10]]; my $w_oset = [[10]]; push @$w_oset, map { $_ %2 == 1 ? [$_] : () } ( 1..19 ); print_oset( $w_oset ); return $w_oset; } sub print_list{ my $Numlist = shift; say "list: ",@$Numlist if @_; # $_[0] == 1; say "list: \[", map("[@$_],", @$Numlist), "\]"; } sub print_oset{ my $Oset = shift; say "oset: ",@$Oset if @_; # $_[0] == 1; say "oset: \{", map("[@$_],", @$Oset), "\}"; }