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

I was expecting it to go UP by 1 each time in the loop, but it stayed at 5. Why?

Because getpgrp returns the current process group.    You want the current Process Id which is in the $$ variable.

Replies are listed 'Best First'.
Re^2: Perl File Handle Count not working as expected, why?
by almut (Canon) on Jul 14, 2010 at 18:10 UTC

    Although correct, this is not the issue here (the process group id and the process id are numerically the same in this case).

    The real issue is that by creating a new $fh with

    my $fh = new FileHandle();

    the old handle will go out of scope, so the file is automatically being closed.

    If you store away $fh somewhere, e.g.

    my $fh = new FileHandle(); push @fhandles, $fh; # keep it from going out of scope ...

    the file handle count will go up.

      THANKS!!!!