| Business-AU-TFN documentation | Contained in the Business-AU-TFN distribution. |
Business::AU::TFN - Validate TFN - Australian Tax File Name
use Business::AU::TFN;
print Business::AU::TFN::validate("123 456 782");
Details come from http://bioinf.wehi.edu.au/folders/fred/tfn.html
Currently these are package methods which must be called explicitly. Although I am considering making this better.
Validate a tax file number. Return value is one of
'valid' - yep, completely valid
'invalid length' - Must be 9 characteres (spaces accepted)
'invalid sum' - does not match
This prints out a valid pretty print of an TFN The standards says that it must be showed in groups of three (nnn nnn nnn).
Scott Penrose <scottp@dd.com.au>
Business::AU::ACN, Business::AU::ABN
| Business-AU-TFN documentation | Contained in the Business-AU-TFN distribution. |
package Business::AU::TFN; use vars qw/$VERSION/; $VERSION = "0.1";
use constant WEIGHT => qw/1 4 3 7 5 8 6 9 10/;
sub validate { my ($tfn) = @_; my @tfn = _split($tfn); # check length is 9 unless (@tfn == 9) { return "invalid length (must be 9)"; } # add accumulation my $acc = 0; for (my $i = 0; $i < 9; $i++) { $acc += $tfn[$i] * (WEIGHT)[$i] } # check it is valid if (($acc % 11) == 0) { return "valid"; } return "invalid sum"; } sub _split { my ($tfn) = @_; $tfn =~ s/\s//g; return split(//, $tfn); }
sub pretty { my ($tfn) = @_; my @tfn = _split($tfn); if (validate($tfn) eq "valid") { return join('', @tfn[0..2], ' ', @tfn[3..5], ' ', @tfn[6..8]); } else { return "invalid"; } }
1;