in reply to Re^3: Import comma delimited file into an array
in thread Import comma delimited file into an array

Hi toolic! Why close the file, if it was open with lexical filehandle (and should be closed when scope goes away?)
[]s, HTH, Massa (κς,πμ,πλ)

Replies are listed 'Best First'.
Re^5: Import comma delimited file into an array (close)
by toolic (Bishop) on Nov 19, 2008 at 14:44 UTC
    In this instance, you are probably correct in that there is no need to close the lexical filehandle. However, I do so out of a force of habit, and because I believe it is a good practice. Here is one reason, according to the documentation for close:
    You don't have to close FILEHANDLE if you are immediately going to do another "open" on it, because "open" will close it for you. (See "open".) However, an explicit "close" on an input file resets the line counter ($.), while the implicit close done by "open" does not.

    Also, there is a good discussion on this topic in the book, Perl Best Practices, Chapter 10 (I/O), in the section titled: "Close filehandles explicitly, and as soon as possible".

Re^5: Import comma delimited file into an array
by Anonymous Monk on Nov 19, 2008 at 14:33 UTC
    close $fh or warn "WHACKO ERROR: CLOSE $file $fh : $file may be corrup +t(incomplete) : $!";