http://qs321.pair.com?node_id=913689


in reply to renaming 1000's of FASTA files

One thing you should always make sure is that for every open file handle you create, you should have a corresponding close. It's good practice. Sorry I couldn't be more helpful.

Replies are listed 'Best First'.
Re^2: renaming 1000's of FASTA files
by Corion (Patriarch) on Jul 11, 2011 at 12:55 UTC

    How is this good practice in Perl?

    I'm genuinely asking this. I have found some good practices for me, like for example that every if block should also have an else block, even if that block just dies, because in the long run, I will need code in that block anyway. But I don't see what bugs closing a file prevents or what diagnostics it helps to create. I neglect checking the result of close(), but that's about the only "benefit" I see.

      But I don't see what bugs closing a file prevents

      Running out of file descriptors?

      $ cat /proc/sys/fs/file-max 386943

      citromatik

        But that's only an issue if you keep the filehandles around, isn't it? You can open lots and lots of files without an explicit close() and I'm not sure where explicitly closing files is better than just having the filehandle get re-opened or fall out of scope:

        for (1..100000) { open my $fh, $0; };
      I neglect checking the result of close(), but that's about the only "benefit" I see.

      close() is where you get the most useful information error-checking wise, especially on writing. Some people I've worked with have even gone as far as suggesting not to error check the opens or writes, just checking close() for efficiency and completeness.

      --Dave