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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-02-24 09:12 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (310 votes). Check out past polls.