I strongly recommend using the /x flag with your large regexen to make them more readable and maintainable. It can help code readability to put the regex into a variable too so the flow logic can be seen easily. Consider:

use strict; use warnings; my $regex = qr| Primary\s\(Reporting\)\s Cp\s*:\s*((?:(?!Set).)*) # Now we can see what's happening Set\s*:\s*((?:(?!Car).)*) # but why are the look aheads needed? Car\s*:\s*((?:(?!Ref).)*) |six; while (<DATA>) { next if $_ !~ $regex; print; }
__DATA__ ==================================================================== Record: 9851329 Version: 2 Timestamp: Sat Feb 11 22:39:43 2006 Primary (Reporting) Cp: 113 Set: 2 Car: 1 Ref: yes Event: 9922 Missing P: Keep: 1 Phase: 0x2fdf Strength: 24 Secondary Sector Information: ==================================================================== Record: 9851330 Version: 2 Timestamp: Sat Feb 11 22:39:43 2006 Primary (Reporting) Cp: 115 Set: 1 Car: 2 Ref: yes Event: 9923 Missing P: Keep: 1 Phase: 0x7d10 Strength: 31 Secondary Sector Information: Slot 1: Keep: 1 offset: 391 Strength: 27 Ref: no Slot 2: Keep: 1 offset: 325 Strength: 38 Ref: no

Prints:

Primary (Reporting) Cp: 113 Set: 2 Car: 1 Ref: yes Event: 9922 Primary (Reporting) Cp: 115 Set: 1 Car: 2 Ref: yes Event: 9923

Note, this is not an attempt to solve you immediate problem - others have done that. It is simply a demonstration of a couple of coding tips.


DWIM is Perl's answer to Gödel

In reply to Re: Need help modifying parse program. by GrandFather
in thread Need help modifying parse program. by awohld

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.