in reply to Unassociated Filehandles and Subroutines

The solutions the others posted are great, but they didn't explain why, or at least not clearly. The problem is that you're using the same file handle (FH) for all of your files, so when you try to close two files, you end up closing the same one twice.

btw, another way of doing it is to use the FileHandle module:
my $fh = FileHandle->new('filename', 'r') or die(...);

There is another problem with your code. When you have an error, you're returning the return value of warn, whatever that is. You should probably either die, or return undef.

Replies are listed 'Best First'.
Re^2: Unassociated Filehandles and Subroutines
by Zaxo (Archbishop) on Sep 22, 2004 at 01:19 UTC
    The problem is that you're using the same file handle (FH) for all of your files, so when you try to close two files, you end up closing the same one twice.

    Actually, each time an unlocalized global file handle is opened, the previously attached file is closed. One name, one handle.

    After Compline,
    Zaxo