in reply to Generate unique file handles

Why not simply use a lexical variable as the file handle?
open my $fh, '<', 'test.out' or die "Can't open test.out: $!";

I don't think your approach works - did you try it?

Replies are listed 'Best First'.
Re^2: Generate unique file handles
by alih110 (Novice) on Aug 20, 2008 at 08:23 UTC
    I have not yet tried it. Following is the issue faced with a fixed file handle name => Since the perl module is called in parallel through LSF, suppose one process finishes reading the file and closes the filehandle while another process is still reading the file, this file handle also gets closed and it never reads the file completely. Thats why I wanted to have unique file handle names. Can I try $fh_$$ so that it generates a unique file handle with process id?
      If LSF starts a new process for each job (and only in this case $$ will actually help you) it's not an issue at all, because perl variables aren't shared across processes. In this case you can even use bare word file handles, although I don't recommend them.

      Even if it uses perl threads, there's no need to worry because variables aren't shared by default.

      (As a side node when you think of a variable variable name, use a hash instead. So instead of the non-working $fh_$$ you'd use my %handles; $handles{$$} = ... instead. But as said above, no need here).