File::Temp gotcha - tempdir vs. newdir

Today I added a bug to a system due to a fundamental difference between File::Temp::tempdir() and File::Temp->newdir().

File::Temp::tempdir( CLEANUP => 1 ); creates a temporary directory that is auto-deleted when the program exits. This means it is almost never the correct function to use for a long running process.

File::Temp::newdir(); creates a temporary directory, represented by a class instance which is auto-deleted when the instance variable goes out of scope. If you want to create a temporary directory that will exist just long enough to complete a task this is the function/method to use.

BradsWiki: Programming Notes/PerlProgramming/FileTempGotcha (last edited 2012-11-26 12:18:49 by BradleyDean)