Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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.

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?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2016-10-28 11:55 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.