for my $key (keys %coll_key_hash) {
foreach my $rec (@recs_read) {
my @fields = split(/\|/, $rec);
if ($fields[0] eq '010') {
if ($fields[3] =~ $key) {
$print_record = 1;
if ($key ne $prev_key) {
$prev_key = $key;
print_record ("CUST-BEG|$seq\n",' ');
}
print_record ("$rec\n",'c');
}
else {
$print_record = 0;
}
}
else {
if ($print_record) {
print_record ("$rec\n",'c');
}
}
}
}
####
for my $key (keys %coll_key_hash){
for my $rec (@recs_read){
my @fields = split(/\|/, $rec);
if($fields[0] eq '010'){
$print_record = 0;
if($fields[3] =~ $key){ #shouldn't this be /$key/ ?
$print_record = 1;
unless($key eq $prev_key){
$prev_key = $key;
print_record ("CUST-BEG|$seq\n",' ');
}
}
}
if($print_record){
print_record ("$rec\n",'c');
}
}
}
##
##
for my $key (keys %coll_key_hash){
for(my $recIdx = 0; $recIdx < scalar @recs_read; $recIdx++){
#check, if redo overflowed the end of an array:
next if(($recIdx + 1) > scalar @rec_read);
my $rec = $recs_read[$recIdx];
my @fields = split(/\|/, $rec);
if($fields[0] eq '010'){
$print_record = 0;
if($fields[3] =~ $key){ #shouldn't this be /$key/ ?
$print_record = 1;
unless($key eq $prev_key){
$prev_key = $key;
print_record ("CUST-BEG|$seq\n",' ');
}
}
}
if($print_record){
print_record ("$rec\n",'c');
#Delete one record at the specified index:
splice(@recs_read, $recIdx, 1);
#Since the record at the current index is deleted, the new record shifted to the same index, so we test it again:
redo;
}
}
}