As for the regex part, I'm not sure since I'm not familiar with using the combo of regexes and the range operator. However, I'd advise going a different route than using the substr command to find the critical data that your trying to key in on. It looks like you're data is somewhat columnar, which means that using split /\s+/ can be used to create an array with each column stored in a different element.

The code below is how I would approach the problem. It kind of looks like you're planning to add more code to do other stuff, which means that the code below would probably need to be modified to fit in with your bigger plan.

Code:

use strict; use warnings; my $infile = "data.txt"; my $outfile = "peptest.txt"; open(DATA,"<",$infile) || die "Unable to open file '$infile': $!\n"; my $file; # Slurp in the file into memory { local $/; $file = <DATA>; } close(DATA); open(OUTPUT,">",$outfile) || die "Unable to open file '$outfile': $!\ +n"; my ($section) = ($file =~ m/(NAME.*)ADJ/is); my (@lines) = split /\n/,$section; my $i = 0; foreach my $line (@lines) { if ($line =~ m/1235114182/) { my (@cols) = split /\s+/,$line; if ($cols[12] eq "0.00") { print OUTPUT "$lines[$i]\n$lines[$i+1]\n"; } } $i++; } close(OUTPUT);

Output file:

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

In reply to Re: Regex Not Grabbing Everything by dasgar
in thread 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":



  • 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.