in reply to Statement Parsing and Rendering
open(my $in_fh = IO::File->new, "<", $infile) or die "Can't open $infile: $!.\n"; close $in_fh; $chunk =~ s/[\f\r\n]//g; my @statement = split '`', $chunk; my %desc = ( 020 => { type => 'single', names => [ 'account'] }, ##didn't know how else to handle + this 200 => { type => 'single', names => [ 'f1', 'f2', 'f3', 'name', 'street', 'place1', 'place2', 'f8', 'f9', 'f10', 'f11', 'email', ' +f13' ] }, 300 => { type => 'single', names => [ 'name_1']}, 500 => { type => 'multiple', names => ['period_start','loan_id','description','loan_ty +pe','beginning_balance_desc', 'beginning_balance','loan_type_num','loan_branc +h','mail_code','loan_code', 'note_num','late_payment_warn_maxfee']}, 510 => { type => 'single', names => ['transaction_date','posting_date','transaction +_desc','transaction_desc_continued']}, 501 => { type => 'single', names => [ 'rate1', 'rate2' ] }, 530 => { type => 'multiple', names => [ 'transaction_date', 'post_date', 'transaction_ +amount', 'late_fee', 'interest', 'balance_change', 'new_balance', 'transaction_ +desc'] }, 539 => { type => 'single', names => [ 'end_loan']}, 540 => { type => 'single', names => ['deposit_count','deposit_amount']}, 541 => { type => 'single', names => ['withdraw_count', 'withdraw_amount']}, 550 => { type => 'multiple', names => ['interest_desc', 'total_int_YTD','total_fees_YT +D', 'loan_fee','interest_fee' ]}, 551 => { type => 'single', names => ['do_nothing'] }, 250 => { type => 'single', names => ['do_nothing'] }, 334 => { type => 'single', names => ['do_nothing'] }, 330 => { type => 'single', names => ['do_nothing'] }, 333 => { type => 'single', names => ['do_nothing'] }, 343 => { type => 'single', names => ['do_nothing'] }, 344 => { type => 'single', names => ['do_nothing'] }, 340 => { type => 'single', names => ['do_nothing'] }, 412 => { type => 'single', names => ['do_nothing'] }, 570 => { type => 'single', names => ['amount_due','due_date']}, 599 => { type => 'multiple', names => ['period_end_date', 'end_balance_desc','end_bala +nce'] }, 690 => { type => 'single', names => ['additional_info'] }, 701 => { type => 'single', names => ['loan', 'end_balance'] }, ); my %data; #$/ = "`\n"; #would not run through the file if I left this on foreach my $line (@statement) { chomp $line; my @fields = split '~\d\d', $line; next unless length $line; next unless scalar(@fields); my $fieldno = shift @fields; if( exists $desc{$fieldno} ) { if( $desc{$fieldno}{type} eq 'single' ) { @{$data{$fieldno}}{ @{ $desc{$fieldno}{names} } } = @field +s } else { push @{ $data{$fieldno} }, {}; @{ $data{$fieldno}[-1] }{ @{$desc{$fieldno}{names}} } = @f +ields } } else { print "Unknown data $fieldno\n"; } } print Dumper \%data;
|
|---|