This code is slightly broken because it ignores a requirement that was specified by the problem (every section starts with a line containing a number which is the number of records) and relies on an assumption instead (every section is terminated by ==== followed by "\n"). There are at least three cases where this would break, and they do happen more often than not.
- When there is a record ending with "====", this code breaks the section into more files than it should.
- When there is a space after the "====", then it won't match the input record separator, thus 2 sections will be merged in one file. This space would not be visible to the eye so debugging this problem is not easy.
- When there is an empty line after the last "====", you will have an additional empty file.
So, the wisdom behind this story: follow the specs carefully and don't golf when you don't need to.
Hope this helps,,,
Aziz,,,