Perl: Create a temporary file that's automatically removed on script termination

I need a random temporary file to put some data in while my script executes. The file should be removed automatically after the script completes. Enter File::Temp which handles all of this for you.

use File::Temp;

my ($fh, $filename) = File::Temp::tempfile(UNLINK => 1);

Alternately if you need a temporary directory that's automatically removed on completion you can use:

use File::Temp;

my $dir = File::Temp::tempdir(CLEANUP => 1);

Note: File::Temp is a core module, so you already have it.

Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
Logged IP:
To prevent spam please submit by clicking the kitten: