B
banker123
I posted this questions earlier in the week, I have cleaned up the code
and incorporated some suggestions however I have not been able to
achieve the objective. The code break when there is ore than one
$invoice and does not match Batch found in the second line of DATA.
DATA (Input)
SAMPLE MINING 352804
$4,668.55 $4,668.55
Batch: 00608623 Seq: 6
Check Serial: 3850917
DONS EQUIPMENT COMPANY 352545 $1,150.84
$1,573.89
Batch: 00608741 Seq: 9 352546
$423.05
Check Serial: 007251
#!/usr/bin/perl
use strict;
use warnings;
open ("DATA", 'C:/data.txt') or die "Cannot open file: $!";
open ("OUT", '>C:/report.txt') or die "Cannot open file: $!";
my $invoice;
while ( <DATA> ) {
if (/\s{8}\d{6}/) {
$invoice = $_;
chomp $invoice;
}
elsif (/\s{2}Batch/ ) {
chomp my $batch;
print OUT "$batch $invoice\n";
}
}
OUT (Output)
SAMPLE MINING 352804 $4,668.55
$4,668.55
Desired Output
SAMPLE MINING 352804 $4,668.55
$4,668.55 Batch: 00608623 Seq: 6
DONS EQUIPMENT COMPANY 352545 $1,150.84 $1,573.89
Batch: 00608741 Seq: 9
Batch: 00608741 Seq: 9 352546 $423.05
Batch: 00608741 Seq: 9
and incorporated some suggestions however I have not been able to
achieve the objective. The code break when there is ore than one
$invoice and does not match Batch found in the second line of DATA.
DATA (Input)
SAMPLE MINING 352804
$4,668.55 $4,668.55
Batch: 00608623 Seq: 6
Check Serial: 3850917
DONS EQUIPMENT COMPANY 352545 $1,150.84
$1,573.89
Batch: 00608741 Seq: 9 352546
$423.05
Check Serial: 007251
#!/usr/bin/perl
use strict;
use warnings;
open ("DATA", 'C:/data.txt') or die "Cannot open file: $!";
open ("OUT", '>C:/report.txt') or die "Cannot open file: $!";
my $invoice;
while ( <DATA> ) {
if (/\s{8}\d{6}/) {
$invoice = $_;
chomp $invoice;
}
elsif (/\s{2}Batch/ ) {
chomp my $batch;
print OUT "$batch $invoice\n";
}
}
OUT (Output)
SAMPLE MINING 352804 $4,668.55
$4,668.55
Desired Output
SAMPLE MINING 352804 $4,668.55
$4,668.55 Batch: 00608623 Seq: 6
DONS EQUIPMENT COMPANY 352545 $1,150.84 $1,573.89
Batch: 00608741 Seq: 9
Batch: 00608741 Seq: 9 352546 $423.05
Batch: 00608741 Seq: 9