in reply to Re: Perl File Handle Count not working as expected, why?
in thread Perl File Handle Count not working as expected, why?

Using plain open, produces the same effect. That is no, close, but still the file handle count remains the same. From the literature, I gather that only IO::File does auto close. I am confused.....Please help.... use strict; my $i = 0; # Get the current Process Id my $proc = getpgrp(0); # Create 10 files.. while ($i < 10) { $i++; # Get a new File Handle # Count the File Handle for this process... system ("ls -l /proc/$proc/fd/ | wc -l"); # Open a new File open (FH, "+>", "/tmp/$i") or die "$!"; # Write something to the file print FH "stuff \n"; #increment counter, to create a newer file. ## NO CLOSE... #print "COunter $i\n"; } 1;
  • Comment on Re^2: Perl File Handle Count not working as expected, why?

Replies are listed 'Best First'.
Re^3: Perl File Handle Count not working as expected, why?
by ikegami (Patriarch) on Jul 14, 2010 at 18:30 UTC

    [ Please use <c>...</c> tags around your code ]

    Switching from a lexical to a global variable changes nothing. You're still overwriting (and thus closing) the previous pass's file handle every time you go through the loop.

    You need to store the the handle somewhere it doesn't get overwritten, such as in an array.