in reply to Safe Temp Files

Thank you all for your kind replies. But I don't see where my basic question was answered.

Which method is safer and/or more reliable? I think they are about the same. Am I correct?

Thanks!

-George

Replies are listed 'Best First'.
Re^2: Safe Temp Files
by xdg (Monsignor) on Dec 05, 2006 at 15:48 UTC

    I would recommend using File::Temp. I think it is equally safe/reliable, gives more portability (to older Perls), and gives more flexibility.

    For example, if you want your temporary files to stick around for inspection during debugging, you can just tell File::Temp not to unlink them on exit if debugging is on.

    use constant DEBUG => 1; my $fh = File::Temp->new( UNLINK => DEBUG ? 0 : 1 );

    If you're in the habit of using File::Temp, you'll always have the full flexibility it gives available to you.

    -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.

Re^2: Safe Temp Files
by Cabrion (Friar) on Dec 06, 2006 at 13:26 UTC
    Can you be more specific about what safe and reliable mean to you? For instance is saftey a matter of hacker-proofing, like the way CGI unlinks it's file handles to avoid spying by others? Is reliability a matter of portability from one OS to another or is it about always getting a unique filename in each situation? Clarifying these might lead to more specific opinions.