Why am I getting a closed filehandle error when using the diamond operator in list context in Perl?

Posted by gvkv on Stack Overflow See other posts from Stack Overflow or by gvkv
Published on 2010-04-24T12:43:55Z Indexed on 2010/04/24 12:53 UTC
Read the original article Hit count: 275

Filed under:
|

This code:

foreach my $file (@data_files) {

    open my $fh, ',', $file || croak "Could not open file $file!\n";
    my @records = <$fh>;
    close $fh;

    ....

}

produces this error:

readline() on closed filehandle $fh at nut_init_insert.pl line 29.

and I have no idea why.

© Stack Overflow or respective owner

Related posts about perl

Related posts about diamond-operator