I already pointed out that AR's version is wrong. You can't rely on readline returning EOF or errors more than once.
I thought mine was better than JavaFan's because it lead to the elimination of the duplicate "g()", but that turned out to be a mistake (as per my earlier update).
I still prefer mine over JavaFan's, though. Since mine flows from top to bottom, it requires less skipping around to follow the code.
| [reply] |
Ah! Now I see what you're saying.
Using AR's code, suppose the file is empty, then the very first while (<FILE>) will return EOF, then the code flows to the second while (<FILE>). There, even though the file pointer is at the end of the file, the <> operator won't return an EOF a second time. And the code in that second while loop will get executed when it should not.
Thinking of it this way, I can now see how both yours and JavaFan's code avoid that trap. Thanks.
| [reply] |