Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: renaming 1000's of FASTA files

by osbosb (Monk)
on Jul 11, 2011 at 12:50 UTC ( #913689=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://913689]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-08-15 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?