in reply to help with the diamond operator

La12, Everyone else has clarified the first method you used, but just for the sake of completeness . . .

The second method (while(1) {) translates roughly to "read and print <$foo> forever". Unfortunately, once you're finished reading the file the while statement doesn't terminate. That's why the program hangs.