in reply to Scoping question - will file handle be closed?

Yes, it should be closed, because you are returning the lines read on $fh.

But if you changed:

local $/; return <$fh>;
to:
# local $/; no longer useful here return $fh;
with the idea of reading from $fh in the caller, then it will clearly remain open.

Replies are listed 'Best First'.
Re^2: Scoping question - will file handle be closed?
by Monk::Thomas (Friar) on Jul 14, 2015 at 20:45 UTC

    I'm aware that returning $fh instead of <$fh> would keep the file handle open. I just wanted to confirm that the normal scoping rules also apply to <$fh> and there is no evil magic trickery going on behind the scenes.

    What kind of evil? Hmm. Maybe <$fh> is actually evaluated lazily and does not return stuff unless someone actually reads from it keeping the $fh open. (Sorry, to much functional thinking recently...)