in reply to slurping styles

It is a good practice to localize the variables to the smallest block possible. Therefore, I prefer the second style. In the first case, if you expand your code and open another file within the same block, you may overlook the setting which is still effective.

Update: I second the others who also recommend to use a lexical for the file handle.