Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8846925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:06:33+00:00 2026-06-14T12:06:33+00:00

I am creating temp files with File::Temp. My temp files are deleted automatically when

  • 0

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.

Here’s a simple program demonstrating my problem.

The desired behavior is this. How can I achieve it? I am on Linux.

  • temp file is not deleted when closing the file handle (ok)
  • temp file gets deleted when program exits normally (ok)
  • temp file gets deleted when program exits with ctrl+c (not working)

.

#!/usr/bin/perl -l

use warnings; use strict;
use File::Temp qw(tempfile tmpfile);

my $fh = File::Temp->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;

EDIT 1

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.

# program will die because os deletes tmpfile after close
my $fh = tempfile;
close $fh;
stat $fh || die;
readline STDIN;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:06:34+00:00Added an answer on June 14, 2026 at 12:06 pm

    To cause a Control_C keyboard interrupt to run your END block you will need to add a signal handler. Compare the behavior of:

    perl -E 'END{say "END"};<STDIN>'
    

    with:

    perl -E '$SIG{INT}=sub{die};END{say "END"};<STDIN>'
    

    From the perlmod

    An END code block is executed as late as possible, that is, after perl has
    finished running the program and just before the interpreter is being exited,
    even if it is exiting as a result of a die() function. (But not if it's
    morphing into another program via exec, or being blown out of the water by a
    signal--you have to trap that yourself (if you can).) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our application has recently started creating (and not cleaning up) temp files at a
I have up to 8 seperate Python processes creating temp files in a shared
I'm creating a temp table that's the result of a stored procedure's result set.
I'm creating a temp image always named 1.png under specific folder and once i
im using linux with gedit which has the wonderful habit of creating a temp
I'm trying to automate MySQL user creation procedure. I thought of creating a temp
In case something goes wrong in creating a file, I've been writing to a
My application now needs to create and then write files to a temp directory
I asked the same question yesterday and the answer was not applicable. https://stackoverflow.com/questions/6194578/breaking-up-class-functions-into-multiple-cpp-files If
I'm developing a console application that parse xml files and generate a txt file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.