in reply to Breaking out of a matching block
As to what you hope to save, there isn't anything that just magically skips a bunch of input lines from the file. Each line has to be read sequentially from the input and this I/O operation is typically the resource intensive "expensive" part. The range operation has a "flip/flop" state that says whether you are within the range or not.
Its not clear to me how you decide what is "cool data" or not? or maybe more to the point how you know all the "cool" data has happened and no more is left in that block?
It could be that you need a different "END" regex? Any valid regex can go there, maybe you need to "end" on either START or END tokens? Or have some term that factors in "all cool data processed"? That would cause range op to start looking for the next START token.
The performance is unlikely to become significantly faster because the "expensive" part is the I/O. Perl regex is very fast. Anyway instead of thinking "break", think about what ending regex would be more appropriate.
Update: It could be that a more traditional parsing would work better instead of the regex range operation for this application.
while (<$fh>) { process_block() if /^START/; } sub process_block { while (<$fh>) { return() if /^END/; return() if "data isn't cool anymore"; #pseudo code ..process cool data.. #pseudo code } }
|
|---|