in reply to using lookaround assertions to grab info
Note that this code is quite simple and will only work if only one section continues accross multiple lines, if you need more than one sections that handles multiple lines the same basic idea can work, but it takes more work.my $section = ''; #remember the last section label we encountered foreach (@m) { if ($_ =~ /^Dig No\s:\s(\w*)\s*Prior:\s*([0-9]*)\s*Digstrt:\s*([0-9]{ +2}\/[0-9]{2}\/[0-9]{2})\s*Time:\s*([0-9]{2}:[0-9]{2})/) { $section = 'Dig No'; $m{'DIG_NO' } = $1; $m{'PRIORITY'} = $2; $m{'DIGDATE' } = $3; $m{'DIGTIME' } = $4; } elsif ($_ =~ /^Address\s*:\s*(.*)Subdivsn/) { $section = 'Address'; $m{'ADDRESS' } = $1; } elsif ($_ =~ /^Remarks\s*:\s*(.*)/ || $section eq 'Remarks') { #do +this if we enter the section or were already in the section $section = 'Remarks'; $m{'REMARKS' } = $1; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: using lookaround assertions to grab info
by punkish (Priest) on Jun 03, 2004 at 21:35 UTC | |
by ryantate (Friar) on Jun 03, 2004 at 21:48 UTC | |
by Ven'Tatsu (Deacon) on Jun 03, 2004 at 21:45 UTC | |
by ryantate (Friar) on Jun 03, 2004 at 21:57 UTC | |
by Ven'Tatsu (Deacon) on Jun 03, 2004 at 22:23 UTC |