B
banker123
I have the following code that parses lines that contain \s{8}\d{5} and
assigns invoice as a variable, the elsif parses lines that contain
\s\sBatch: and assign the batch and seq to a hash. This code works
when I have one invoice, however the code breaks (does not parse the
second invoice) when more than one invoice is present.
my %batches;
while ( <DATA> ) {
if (/\s{8}\d{5}/) {
$invoice = substr($_,32,14);
}
elsif (/\s\sBatch:/ ) {
$batch = substr($_,9,8);
$seq = substr($_,22,4);
$batches{ $batch } = {
seq => $seq,
invoices => [],
};
print "$batch $seq $invoice\n";
}
push @{ $batches{ $batch }{ invoices } }, $invoice;
}
$batches{ $batch }{ seq } and @{ $batches{ $batch }{ invoices } }
DATA INVOICE
BOBS FOODS 352491 $42.50
$942.50
Batch: 00608623 Seq: 17 352650 $900.00
Check Serial: 880587
assigns invoice as a variable, the elsif parses lines that contain
\s\sBatch: and assign the batch and seq to a hash. This code works
when I have one invoice, however the code breaks (does not parse the
second invoice) when more than one invoice is present.
my %batches;
while ( <DATA> ) {
if (/\s{8}\d{5}/) {
$invoice = substr($_,32,14);
}
elsif (/\s\sBatch:/ ) {
$batch = substr($_,9,8);
$seq = substr($_,22,4);
$batches{ $batch } = {
seq => $seq,
invoices => [],
};
print "$batch $seq $invoice\n";
}
push @{ $batches{ $batch }{ invoices } }, $invoice;
}
$batches{ $batch }{ seq } and @{ $batches{ $batch }{ invoices } }
DATA INVOICE
BOBS FOODS 352491 $42.50
$942.50
Batch: 00608623 Seq: 17 352650 $900.00
Check Serial: 880587