Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: renaming 1000's of FASTA files

by Corion (Pope)
on Jul 11, 2011 at 12:55 UTC ( #913692=note: print w/ replies, xml ) Need Help??


in reply to Re: renaming 1000's of FASTA files
in thread renaming 1000's of FASTA files

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.


Comment on Re^2: renaming 1000's of FASTA files
Select or Download Code
Re^3: renaming 1000's of FASTA files
by citromatik (Curate) on Jul 11, 2011 at 16:14 UTC
    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 like explicit closes. I like explicit lots of things that Perl auto-does if given a chance.

        On the maintainability front, an explicit close() tells the maintainer that the author "meant to do that" and "here". No explicit close leaves questions. Did they mean to let it close automagically, or did they leave out the close where they really wanted it, etc.

        I rarely have the luxury of working with expert Perl programmers. The more that's done explicitly and clearly, the better for everyone involved.

        --Dave

Re^3: renaming 1000's of FASTA files
by armstd (Friar) on Jul 13, 2011 at 14:20 UTC
    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
Node Status?
node history
Node Type: note [id://913692]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (16)
As of 2014-08-27 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (238 votes), past polls