in reply to Re: Safe Temp Files
in thread Safe Temp Files

advantage of open is that its syntax is simpler

I'm not convinced of that. Apart from the "use" line, the File::Temp approach is about the same length and the intent is more immediately obvious.

open(my $fh, "+>", undef) or die ...
use File::Temp (); my $fh = File::Temp->new or die ...

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^3: Safe Temp Files
by bart (Canon) on Dec 05, 2006 at 11:27 UTC
    the File::Temp approach is about the same length and the intent is more immediately obvious

    I disagree on the latter. new is the worst name for a method, for a module like this, so a line like this:

    my $fh = File::Temp->new
    is always enough to make me go "WTF...?".

    I wish the module author had put some more inspiration in the name for the constructor, like Tim Bunce used "connect" in DBI instead of the plain, boring and somewhat obscure "new". I like this a lot better.

      I guess I'm used to the convention of using "new" as a constructor and just mentally parse it backwards as "a new Temp File".

      In the Pod, the author writes it in the indirect notation:

      my $fh = new File::Temp;

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.