Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Why do we nned to close filehandles?

by kejohm (Hermit)
on Apr 30, 2011 at 05:32 UTC ( #902131=note: print w/ replies, xml ) Need Help??


in reply to Why do we need to close filehandles?

Perl will usually automatically close any open file handles at the end of the script, so most of the time, you don't have to bother. The only trouble comes when you need to open a large number of files concurrently. Most operating systems have a limited number of file handles available, so if you fail to close any open file handles, you may run out, which isn't easy to recover from. Conveniently, in newer versions of Perl, storing a file handle in a lexical variable will cause the file handle to be automatically closed when the variable goes out of scope, e.g.

if(open my $fh, '<', $file){ # process file } # file will be closed when we reach here

Check out open and close for more info.

Update: Links fixed.


Comment on Re: Why do we nned to close filehandles?
Download Code
Re^2: Why do we nned to close filehandles?
by Anonymous Monk on Apr 30, 2011 at 05:38 UTC
    FileCache - keep more files open than the system permits

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://902131]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-12-20 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (94 votes), past polls