Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening two filehandles with same filehandle name

Status
Not open for further replies.

bobbybobbertson

Programmer
Nov 9, 2001
119
US
I just realized that I have a foreach statement in a bunch of my perl scripts that open a filehandle without closing it. The scripts work fine, but is there a need to fix this?
Or does perl automatically close a filehandle when another with the same name is opened?

my statement looks as follows:

foreach my $file_to_open (@files_to_open) {
open LOGFILE, $file_to_open or die "nogood $!";
#do work here
}
 
Not sure what will happen, but what's the harm in just including the line close LOGFILE; at the end of your loop?
 
doesn't usually matter

but... (and you knew this was coming....)

I had a script running on cron, every minute of every day.

ran through a directory opening all of the files - doing stuff and then terminating.

worked fine, no problems, for two years and then I upgraded from HPUX 10.10 to 10.20 and it failed horribly - the kernal ran out of file handles

so.... now I always close files Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Is there a way to to see on a linux server how many file hanles are currently open? and what programs have them open?
 
[Dont know if Perl can override these settings]

The maximum number of files that a process can open is defined by _SC_OPEN_MAX is unistd.h;

'man sysconf' has more on that.

<Not sure>
For POSIX standards , I think a single process can open a maximum of 63 files at any time.
</Not sure>


Help anybody?

regards
C &quot;Brahmaiva satyam&quot;
-Adi Shankara (788-820 AD)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top