in reply to Parse Loops with flat text files. (code)

Two comments.

First of all isbeg and isend are names that grate on me. In general if you provide visual separation for what are supposed to be separate words, people find it easier to read. So I would be inclined to name them is_beg and is_end. A more subtle issue that I have found is that when I abbreviate, I sometimes abbreviate inconsistently. I have enough code, and I am surrounded by enough, that I usually don't worry about it. But I am seriously considering longer names. In which case I would write is_begin instead of is_beg. (I haven't tried that last though, I may feel differently on it tomorrow.)

Beyond that you have a lot of state that seems spread out across multiple places of the code. And what is worse is that the state is done in a way where you have no choice but to slurp up the whole file. Depending on whether you ever expect to hit a large file, you may not care. But if you do then you may want to consider how to incrementally process the file. With this you would want to consider your filehandle as an infinite stream, wrap that in an object that reads through the filehandle, reading as needed, which knows how to filter and returns wanted values as long as there are more of them. And then in the main body of your code you could loop over the output of your filter. (If you wanted you could even make this a tied handle.)

Now here are three random links that each relate in some way to what I just outlined above. Be warned. None of them apply to how to implement the above in Perl (which you should be able to figure out), but each one applies in some way to either the problem or the proposed solution. Each one opens up some issue or concern. And if all else fails, I found each one interesting...

  • Comment on Re (tilly) 1: Parse Loops with flat text files. (code)