Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Regex Not Grabbing Everything

by JonDepp (Novice)
on Sep 20, 2010 at 18:21 UTC ( [id://860910]=note: print w/replies, xml ) Need Help??


in reply to Re: Regex Not Grabbing Everything
in thread Regex Not Grabbing Everything

Thanks so much for your reply and explanation. My style and confusing code stems from the fact that I started teaching myself Perl a few months ago.

Your code works great. The only problem I have is that it doesn't grab those N347 and N265 codes that are in between the lines. That is why I wanted to print the whole of NAME...ADJ TO TOTALS because it included those codes. Is there a way to include grabbing those N codes as part of the @lines array? I tried to grep those codes and add them to the print statements but they don't line up correctly (the lines they correspond to are directly above the code lines). That is why I thought of using the substring in order to test for the 0.00 condition and grab all the information. Do you think I need to add another if conditional or modify the @lines array to grab those N codes in the right spot?

Replies are listed 'Best First'.
Re^3: Regex Not Grabbing Everything
by Marshall (Canon) on Sep 20, 2010 at 20:29 UTC
    To get the next line after a line ending in 0.00,
    if (my @lines = grep{/^\d+.*\s*0\.00\s*$/}@data) change to: if (my @lines = grep{/^\d+.*\s*0\.00\s*$/..././}@data)
    Perl grep is a very powerful critter! What the above says is to filter lines from @data. If the condition in the grep is true, make a copy of the line in @lines. The regex in the grep means: True if we are inbetween a line starts with a digit and ends with 0.00 and another line containing any character at all. The 3 dots means that this "any character" has to be on a separate line. So this will print the line ending in 0.00 and the next line whatever it has, which from your data format happens to be this N347 stuff! Pretty cool!

    As like before, I deleted some of the characters so that the output wouldn't word wrap.

    NAME DOE, JOHN ..... ASG Y MOA MA01 MA18 12351141821118 ..... CO-18 31.00 0.00 N347 12351141821118 ..... CO-18 199.00 0.00 N347 12351141821118 111809 CO-18 182.00 0.00 N347 ADJ TO TOTALS: PREV PD INTEREST ... 84.25
    I wish you well on your Perl learning adventure! Perl is certainly not considered a beginning language. So you are starting in a hard place. You will need a number of books, perhaps start with "Learning Perl".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://860910]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-26 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found