title: How to automatically delete files created with File::Temp when program stops unexpectedly?
body: <p>I am creating temp files with File::Temp. My temp files are deleted automatically when the program exits normally. I expected the same to happen when my program is stopped with ctrl+c. It is not. </p>
  
  <p>Here's a simple program demonstrating my problem. </p>
  
  <p>The desired behavior is this. How can I achieve it? I am on Linux.</p>
  
  <ul>
  <li>temp file is not deleted when closing the file handle (ok)</li>
  <li>temp file gets deleted when program exits normally (ok)</li>
  <li>temp file gets deleted when program exits with ctrl+c (not working)</li>
  </ul>
  
  <p>.</p>
  
  <pre><code>#!/usr/bin/perl -l
  
  use warnings; use strict;
  use File::Temp qw(tempfile tmpfile);
  
  my $fh = File::Temp-&gt;new;
  close $fh;
  
  -f "$fh" || die "$fh does not exist"; 
  print "hit enter and the file will be deleted";
  print "hit ctrl+c and it won't";
  print "verify with ls $fh after program exits";
  readline STDIN;
  </code></pre>
  
  <p>EDIT 1</p>
  
  <p>I tested the behavior of tempfile. It seems to confirm that Linux supports what I am looking for (marking files as temp / unlinking open file). I seem to have idealized File::Temp somehow.</p>
  
  <pre><code># program will die because os deletes tmpfile after close
  my $fh = tempfile;
  close $fh;
  stat $fh || die;
  readline STDIN;
  </code></pre>