in reply to regex help, please
Anyway a "read the line and throw it away" if not needed is much faster than a "slurp" and substitution. A simple formulation of this is shown below.
Update: I would also add Flipin good, or a total flop? as another way along the way of shem's approach. The three dot (...) version of the "flip flop" syntax works with multiple lines, the (..) version works with single lines.
#!/usr/bin/perl -w use strict; my $line; while ($line = <DATA>) { skip_record() if $line =~ m/^\s*CD_TEXT/; print $line; } sub skip_record { while ($line = (<DATA>), $line !~ m|^\s*//\s*Track|){}; } #prints: # CD_DA # # // Track 1 __DATA__ CD_DA CD_TEXT { LANGUAGE_MAP { 0: 9 } LANGUAGE 0 { TITLE "Multi-01" PERFORMER "" SIZE_INFO { 1, 1, 19, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 7, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0} } } // Track 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex help, please
by mchampag (Acolyte) on Dec 21, 2009 at 18:18 UTC |