Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^4: Regex Not Grabbing Everything

by JonDepp (Novice)
on Sep 17, 2010 at 16:24 UTC ( [id://860522]=note: print w/replies, xml ) Need Help??

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

There is a space for numbers that are five characters in the substring. I changed the 5 to 4 and got 0.0. I used your code and got an empty output file. The first IF statement couldn't have a found in there because the condition that makes the statement true is in the substring deeper in the code. My original code returns what I want in the order I need it but stops before the end of the regex. I commented out different parts of the code to see if the array I was pushing $_ to from the regex was capturing everything, and it is. The code prints out everything I need up until I check for the 0.00 condition. After that it prints out if the 0.00 condition is true but truncates the array before the "ADJ TO TOTALS" line. Is there a reason why testing for that substring condition would truncate the array?

Replies are listed 'Best First'.
Re^5: Regex Not Grabbing Everything
by japhy (Canon) on Sep 17, 2010 at 17:23 UTC
    If changing the 5 to 4 yields '0.0', then I think it's actually yielding ' 0.0' (that's space-zero-dot-zero), which means your offset of 118 might be wrong.

    The reason your code is failing, in general, is because your logic is faulty. You think your code is saying "print the contents of the array if there's a line with '0.00' at offset 118", but your code is NOT saying that.

    Your code is saying:

    for each line in between 'NAME' and 'ADJ TO TOTALS:', do this { add this line to the @data array now go through each element of the @data array, and do this { # <-- + WHY?! if this line has 1235114182 in it, do this { put this line at the end of $lines if $lines has '0.00' at offset 118, do this { print the @data array } empty the @data array, $lines, etc. } } }
    Your code is faulty because it won't print any line that DOESN'T have '0.00' in it.

    I suggest you try my sample solution and plug in the values for $target, $pos, 'START', and 'END'.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    Nos autem praedicamus Christum crucifixum (1 Cor. 1:23) - The Cross Reference (My Blog)

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-05-25 08:12 GMT
Find Nodes?
    Voting Booth?

    No recent polls found