Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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!!

In reply to Regex Not Grabbing Everything by JonDepp

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found