Keep It Simple, Stupid | |
PerlMonks |
Re: A way to report open file handles a Perl script has open? -- using ${^LAST_FH} ?by Discipulus (Canon) |
on Apr 05, 2017 at 08:39 UTC ( [id://1187076]=note: print w/replies, xml ) | Need Help?? |
Hello nysus, For sure the best thing to do is to open always lexical filehandles to let Perl close them for you. The habit to close them esplicitally is a sane one anyway. Extra scope can help if you have many declared into the top scope. But the strange behaviour you announce (leaking file handles like a sieve) I'd expand the mr_mischief's solution: take count of what you open. You can override open builtin function very soon in the program or in a BEGIN block, and you can profit of the ${^LAST_FH} special variable: if I understand the doc correctly it tracks the last open $fh (only read-fh ?) taking a reference to it You probably need to override close to erase from your tracking variable. An END block can dump the tracking datastructure. So given a %fhs in the outher scope you can store there your fh
PS sorry the node was composed on a spare PC where was impossible to test anything.. L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Seekers of Perl Wisdom
|
|