in reply to reading multiple files one at a time

Strange but true: You don't have to close the files as the next open F will close it. BUT: if you want $. to reflect the line numbers of _each_ file (that is start over at 1 on the first line of each file), then you do have to close it.

Replies are listed 'Best First'.
Re: Re: reading multiple files one at a time
by MZSanford (Curate) on Jul 18, 2001 at 13:14 UTC
    Quite some time ago, writting into several diffrent files from a function which opened each time, i had a problem were data would not fluch correctly. My only guess at the time was that the implicit close on my version of Perl was not flushing to disk. Not sure this is the correct cause, but adding the single close line fixed it, so i always explicitly close filehandles ... just a warning.
    OH, a sarcasm detector, that’s really useful
Re: Re: reading multiple files one at a time
by Hofmator (Curate) on Jul 18, 2001 at 15:29 UTC

    The 'extra' close allows for error checking as well, that's why it's a good idea to keep it - of course only if you really check for errors ;) close FILE or die "Couldn't close file: $!";

    If you nevertheless want the continous counting of lines a la $. it shouldn't be a problem to do that yourself with something like $linecount++

    -- Hofmator