On Wed, Aug 21, 2024 at 8:14 AM Jeff King <peff@xxxxxxxx> wrote: > On Wed, Aug 21, 2024 at 03:00:05AM -0400, Eric Sunshine wrote: > > I'm surprised that we're not closing the two file handles opened on > > each iteration of this loop. Is that intentional? Or am I forgetting > > my Perl and they are somehow getting closed anyhow (for instance, by > > the <...> operator hitting EOF)? > > They're scoped to the loop with "my", so they'll both be closed for each > iteration of the outer loop when the handles go out of scope. Makes sense. I thought that might be the case but it's been years since I read the "camel book" (thus may have forgotten it), and wasn't able to find any Perl documentation which stated so (which is not to say such documentation doesn't exist, but rather that I couldn't find it). > You can verify with something like: > > touch foo bar baz > strace -e openat,write,close \ > perl -e ' > for my $script (@ARGV) { > syswrite(STDOUT, "opening $script"); > open(my $in, "<", $script); > syswrite(STDOUT, "finished $script"); > } > ' foo bar baz >/dev/null > > which should show: > > write(1, "opening foo", 11) = 11 > openat(AT_FDCWD, "foo", O_RDONLY|O_CLOEXEC) = 3 > write(1, "finished foo", 12) = 12 > close(3) = 0 > write(1, "opening bar", 11) = 11 Thanks for illustrating. I did think of `strace` but I never use it because it doesn't exist on macOS and I was too lazy to spin up a Linux VM and read the `strace` documentation to figure out how to do what you did above.