I am trying to write a script to parse a trial balance sheet. The layout of each line in the file is always the same but I am having an issue getting my regex to match properly. The first 10 characters of the line are always the account number. Here is an example:
0000000099 S000 Doe, John 00 1,243.22 01/01/1901
I am trying to capture each of these to columns to a separate variable, but my expressions aren't working.
Here is what I have so far.
#!/usr/bin/perl -w
use strict;
my $filename = "S:\\TELLERS\\GalaxyDown\\tbal";
my $answer = undef;
open(FIN, $filename) || die "File not found";
do {
print "Enter an account number: ";
chomp(my $acctNum = <STDIN>);
if ($acctNum =~ /\d{1,10}/) {
$acctNum = pad_zeros($acctNum);
#print "$acctNum\n"; #test to make sure the padding extends the account
#number to 10 digits - comment out after verification
while (<FIN>) {
#print "$_\n";
if (m/(^[0-9]{10}/) {
print "Passed\n";
}
else {
print "Failed\n";
}
}
}
else {
print "Invalid account number. Please try again.\n";
}
print "Would you like to view another account balance? (yes/no): ";
chomp($answer = lc <STDIN>);
} while ($answer ne "no");
sub pad_zeros {
my $optimal_length = 10;
my $num = shift;
$num =~ s/^(\d+)$/("0"x($optimal_length-length$1)).$1/e;
return $num;
}
Any help would be appreciated.
(before the^