Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: A way to report open file handles a Perl script has open?

by talexb (Canon)
on Apr 04, 2017 at 18:15 UTC ( #1187030=note: print w/replies, xml ) Need Help??


in reply to A way to report open file handles a Perl script has open?

Once approach that I can recommend is to open your files inside a scope; once the scope ends, the file handle will automatically be closed. of course, I prefer to explicitly close files handles, but that's just my C background. Something like this:

use autodie; ... my $config_object; { open ( my $config_fh, '<', 'hello.cfg' ); while ( <$config_fh> ) { .. parse config file .. $config_object{ $key } = $something; } } # File handle is now out of scope and therefore closed ..
That's a simple example .. but perhaps you can expand on your question .. why do you think that open file handles are causing you problems?

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1187030]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2018-06-18 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (111 votes). Check out past polls.

    Notices?