ACH-Parser
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
USING ACH-Parser
use ACH::Parser;
my $file = 'RETODC0104A.ACH';
my $ach = new ACH;
$ach->parse($file);
METHODS
parse
Parses the ACH data into the ACH object
CAVEATS
This package is created for testing purposes only. It shouldn't be used
for production programs or scripts. There are other commercial products
out there that may be a more efficient solution for accomplishing your
goals.
All records in an ACH file must be formatted in the following sequence
of records. IF the file is not formatted in this exact sequence, it
may be rejected.
lib/ACH/Parser.pm view on Meta::CPAN
use ACH::Parser;
my $file = 'RETODC0104A.ACH';
my $ach = new ACH;
$ach->parse($file);
=head1 METHODS
=head2 parse
Parses the ACH data into the ACH object
=cut
# Parse the ACH file formatted text into an ACH object
sub ACH::parse {
# Get the file name
my $self = shift;
my $file = shift or _croak "Need an ACH file";
# Open the file
if ( open(INPUT, "$file") ) {}
else { print "Error: Couldn't open file $file\n"; die; }
# Get the file contents
my @data = <INPUT>;
my $dataline = $data[0];
my $pos = 0;
# Loop Through all entries
while ($pos < length($dataline)) {
# Get the correct ACH format array and store all parsed data in a hash
my $desc = substr($dataline, $pos, 1);
my @dataArray = [];
# Make sure file descriptor is valid
if ($desc != 1 and $desc != 5 and $desc != 6 and $desc != 7 and $desc != 8 and $desc != 9) {
die "File Error: Code: $desc\n";
}
# Iterate through the appropriate ACH file format array and parse the data
for (my $x=0; $x < @{$self->{_achFormats}{$desc}}; $x++) {
my $field = ${$self->{_achFormats}{$desc}}[$x];
# Get the field name and length
my ($field_name, $field_length);
while ( my ($key, $value) = each(%$field) ) { $field_name = $key; $field_length = $value; }
# Get the ACH Data from the file
my $part = substr($dataline, $pos, $field_length); chomp $part;
my %hash = ($field_name => $part);
$dataArray[$x] = \%hash;
$pos += $field_length;
}
# Save data to list
@{$self->{_achData}}[scalar @{$self->{_achData}}] = \@dataArray;
}
# Close the Input file
close (INPUT);
}
=head2 CAVEATS
This package is created for testing purposes only. It shouldn't be used
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.933 second using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )