I need remove lines of file where string 406 or 408 is found in the line based on a key. Example of a line to remove is:

4201034600051 1212104069140 001

The key is 1034600051 the account number. The string to check for is 406 is the rev code.

A sample input file looks like this:

201034600051 1212104069140 001 + 4201034600051 1212104039139 001 + 4201034600153 1212104039140 001 + 4201034000375 1212104034111 001 + 4201034000375 1212104033180 001 + 4201034000375 1212104039443 001 + 4201034000375 1212104039232 001 + 4201034600039 1212104039336 001 + 4201034600045 1212104039252 001

Output codes looks like this

CH 01034600051 1212104069140 001 LAB CH 01034600051 1212104039139 001 LAB CH 01034600153 1212104039140 001 LAB CH 01034000375 1212104034111 001 LAB CH 01034000375 1212104033180 001 LAB CH 01034000375 1212104039443 001 LAB CH 01034000375 1212104039232 001 LAB CH 01034600039 1212104039336 001 LAB CH 01034600045 1212104039252 001 LAB

I don't want the line CH 01034600051 1212104069140 001 LAB to be returned because rev code 406 was found

So, I batch up lines where account is the same (can occur mulitple times) and if the line contains 406 or 408 rev code I need to remove the line and not send to output file. Here is the code I have written so far:
use warnings; use strict; my $file_to_process = $ARGV[0]; my $file_to_create = $ARGV[1]; my $curr_acctn = {}; my $first_time = "yes"; my @account_list = (); open FH1, ">$file_to_create" or die "Cannot create $file_to_create"; open FH, $file_to_process or die "Cannot open $file_to_process"; while (<FH>) { chomp; &rtrim($_); my @fields = split; my $acctn = substr($fields[0],3,10); if($acctn != $curr_acctn) { if($first_time eq "yes") { $first_time = "no"; } else { #print FH1 "**************************\n"; #print FH1 "Charges for account number ----> $curr_acctn:\n"; foreach my $account (@account_list) { my $charge_code = substr($account,20,7); my $chrg_credit = substr($account,0,2); if ($chrg_credit == 42) { substr($account,0,2) = "CH "; substr($account,32,3) = " LAB"; } else { substr($account,0,2) = "CR "; substr($account,32,3) = " LAB"; } #print FH1 "The charge or credit is: $chrg_credit\n"; #print FH1 "The charge code is: $charge_code\n"; print FH1 "$account\n"; } @account_list = (); } } $curr_acctn = $acctn; push (@account_list, $_); } close FH; close FH1; sub rtrim() { $_ =~ s/\s+$//; return; }

I add some other things to the output and remove trailing spaces. I just can not figure out how to get rid of the lines with 406 or 408 rev codes

THANKS


In reply to Removing element of an array by cesear

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.