I'm not sure what you mean. As soon as the SIG{INT} handler is installed and I press CTRL-C while your program sleeps I can see the output of the sig handler ('Delete') and the output of the DESTROY method ('In DESTROY()').

To your second question:

#!/usr/bin/env perl use strict; use warnings; use 5.010; $SIG{INT} = sub { say "Caught a signal"; exit 1; }; say "Program started"; say "Starting to sleep"; sleep 3; say "I've been sleeping long enough"; END { say "I'm in the END block"; }

This code should give you confidence. In my case (Linux) the END block is executed.

I'm not sure whether you mix up the creation of a temp directory and temp file. You can create a temp file in your pwd and unlink it with:

my ($fh, $filename) = tempfile($template, DIR => '.'); unlink $filename;

As long as $fh is open you will have a file to write to and read from.

Have a look at:

#!/usr/bin/env perl use strict; use warnings; use 5.010; use Cwd (); use Fcntl (); use File::Temp qw(tempfile); my $pwd = Cwd::getcwd; say "pwd: $pwd"; my $template = 'somthing.XXXXXXX'; my $dir = '.'; my ($fh, $filename) = tempfile($template, DIR => $dir); say "filename: $filename"; system("ls -l '$filename'"); unlink $filename; system("ls -l '$filename'"); say "Now store 'Put some text in' in the file"; print $fh "Put some text in\n"; say "Written to file, try to read"; seek $fh, Fcntl::SEEK_SET, 0; while(my $line = <$fh>) { print "Found in file: $line"; } close $fh; say "End of prog";

McA


In reply to Re^4: DESTROY on CTRL+C by McA
in thread DESTROY on CTRL+C by gri6507

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.