http://qs1969.pair.com?node_id=860485

JonDepp has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I have a file that is set up in the following way:

REND PROV SERV DATE POS NOS PROC MODS BILLED ALLOWED + DEDUCT COINS GRP/RC AMT PROV PD ______________________________________________________________________ +__________________________________________________________ NAME DOE, JOHN HIC 1111111111 ACNT 1111111 + ICN 1111111111111 ASG Y MOA MA01 MA18 12351141821118 111809 23 001 71010 26 31.00 0.00 + 0.00 0.00 CO-18 31.00 0.00 + N347 12351141821118 111809 23 001 70450 26 142.00 44.70 + 0.00 8.94 OA-45 97.30 35.76 + N265 + PR-2 8.94 12351141821118 111809 23 001 74150 26 199.00 0.00 + 0.00 0.00 CO-18 199.00 0.00 + N347 12351141821118 111809 23 001 72192 26 182.00 0.00 + 0.00 0.00 CO-18 182.00 0.00 + N347 12351141821118 111809 23 001 72131 26 195.00 60.61 + 0.00 12.12 OA-45 134.39 48.49 + N265 + PR-2 12.12 PT RESP 21.06 CLAIM TOTALS 749.00 105.31 + 0.00 21.06 643.69 84.25 ADJ TO TOTALS: PREV PD INTEREST 0.00 LATE +FILING CHARGE 0.00 NET 84.25 CLAIM INFORMATION FORWARDED TO : XXXXXX XXXXXXXX INSURANCE CO

I'm using the following code to grab part of this file and test a substring to match one of the 0.00 in a certain spot.

use strict; use warnings; print "What file do you want parsed? "; my $file=<STDIN>; my @data; my $data; my $lines; open (TEST,"$file") or die$!; open OUTPUT, "> peptest.txt" or die$!; while (<TEST>) { if (/NAME /../ADJ TO TOTALS:/) { push @data, $_; foreach $data (@data) { if ($data =~ /1235114182/) { $lines.=$_; my $zero = substr $lines, 118, 5; if ($zero == "0.00") {print OUTPUT "@data \n";} $zero=""; $lines=""; $data=""; @data=(); } } } } close TEST; close OUTPUT;

The output I'm getting is the following:

NAME DOE, JOHN HIC 1111111111 ACNT 111111 + ICN 1111111111111 ASG Y MOA MA01 MA18 12351141821118 111809 23 001 71010 26 31.00 0.00 + 0.00 0.00 CO-18 31.00 0.00 + N265 + PR-2 8.94 12351141821118 111809 23 001 74150 26 199.00 0.00 + 0.00 0.00 CO-18 199.00 0.00 + N347 12351141821118 111809 23 001 72192 26 182.00 0.00 + 0.00 0.00 CO-18 182.00 0.00

What is wrong with the code or regex that its not grabbing everything up to "ADJ TO TOTALS"?

Thanks in advance!!