in reply to Need help modifying parse program.
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.
|
|---|