in reply to Re^2: Parsing out mulitiple blocks of interesting data in files / ignoring other contents
in thread Parsing out mulitiple blocks of interesting data in files / ignoring other contents

The flag variable $in_block keeps track of whether the current line is in a block of interest (because it began with a line starting with the word interface). If we are currently not in such a block, the only thing to be done is to test the current line to determine whether it begins a new such block (if (/^interface/)). If we are already within a block of interest, we will store the current line in the @block array unless the current line (1) begins with the block termination character, !, or (2) begins (after optional whitespace) with the block discard word shutdown.

When condition (1) is satisfied, we know that the current block has terminated successfully, so we print it out. But if condition (2) occurs, the current block is to be ignored. In either case, the block has ended so we reset the flag to indicate that we are no longer within a block of interest.

As mentioned above, if we are within a block of interest but the current line satisfies neither condition (1) nor condition (2), then we save the line by pushing it onto the array variable @block, which holds all the lines of the current block that we have read so far. Whenever condition (1) or condition (2) is satisfied, the block ends so we empty the array @block by assigning the empty list to it: @block = ().

Hope that’s a little clearer,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

  • Comment on Re^3: Parsing out mulitiple blocks of interesting data in files / ignoring other contents
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: Parsing out mulitiple blocks of interesting data in files / ignoring other contents
by GeorgMN (Acolyte) on Mar 02, 2016 at 14:04 UTC
    Thank you very much sir. Very helpful. Have a nice day.