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), "\}"; }

In reply to Re: ABN checker by Don Coyote
in thread ABN checker by bgroper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.