Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Why do we nned to close filehandles?

by kejohm (Hermit)
on Apr 30, 2011 at 05:32 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://902131]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-25 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found