Nope, not homework. Yes, it is snippets of a larger script...these are just some examples of what I got to work but know there is a better way.
Yes, I did forget the closing brace but, as I said, its just a snippet. However, I wonder why its bad to close the infile to exit the loop? It does two things, closes the file and exits the loop.