Re: opening a file



On 2009-01-14, cartercc <cartercc@xxxxxxxxx> wrote:
On Jan 10, 8:07 am, Tad J McClellan <ta...@xxxxxxxxxxxxxx> wrote:
You should always, yes *always*, check the return value from open():

Like other ironclad rules, this also has exceptions. Using the 'or
die' construct has costs (albeit minimal) and when the costs outweigh
the benefit, you shouldn't use it. Example: opening the file is
tangential to the script so you don't care whether the file opens but

If you don't care whether the file opens, why are you opening it?
At the very least I think you'd need to know it didn't open so you
don't attempt to do I/O with it.

you DO care if the script dies.

Not every instance of checking what open() returns is done with "or die".
If you don't want the script to die, don't. But it is difficult in the
extreme to visualize a case where whether or not a file opened makes absolutely
no difference in what the rest of the script needs to do.

--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
.



Relevant Pages

  • Re: opening a file
    ... Like other ironclad rules, this also has exceptions. ... die' construct has costs and when the costs outweigh ... you DO care if the script dies. ...
    (comp.lang.perl.misc)
  • Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
    ... the same task) the specifics of my challenge and the script I am ... script parses a single Palm Desktop-exported vCard file having multiple ... or die "Cannot open '$sourcefilename' $!"; ...
    (comp.lang.perl.misc)
  • Re: finding compile time errors
    ... It looks a *lot* like the Perl DBI module which might be the ... Is there a die in PHP with an error message? ... Of course there's a way to kill a script with dieand an error ...
    (comp.lang.php)
  • Update von JMS zu B5:TLT
    ... Ein neues update-posting von JMS. ... Wer sich für die non-B5 Projekte von ... script, and we've now spoken to several of the original cast members, ... Also erstmal mit den Schauspielern verhandeln, die mitmachen ...
    (de.rec.sf.babylon5.misc)
  • Re: Why does Net::SFTP trigger my die handler when no errors?
    ... Kindly consider, if you please, this trivial sample script ... I have defined a custom "die" handler. ... So it would be my guess that Net::SFTP is dying from inside an eval, ... why are you using a SIG die handler, rather than eval, to do whatever it ...
    (comp.lang.perl.misc)