in reply to Re: Generate unique file handles
in thread Generate unique file handles

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?

Replies are listed 'Best First'.
Re^3: Generate unique file handles
by moritz (Cardinal) on Aug 20, 2008 at 08:28 UTC
    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).