The removal is completed and disk space released once your program closes.
I believe the removal is happening even earlier -- after the program has compiled, and the Perl interpreter has started executing it, but potentially long before the program completes.  Try this to see what I mean:
#!/usr/bin/perl -w + # Strict use strict; use warnings; + # Main program print "Check file before unlink\n"; sleep 1; system("ls $0"); print "Unlinking the file $0\n"; sleep 1; unlink $0; print "Check file after unlink\n"; sleep 1; system("ls $0"); + print "File should be now be gone from disk (but still in memory)\n"; print "Try ^Z and check it with 'ls $0' ... (come back with 'fg')\n"; sleep 10; + print "I'm still here, but the original file is long gone.\n";
And when you run it:
% chmod +x rmtest
% rmtest
Check file 'rmtest' before unlink
rmtest
Unlinking the file 'rmtest'
Check file 'rmtest' after unlink
ls: rmtest: No such file or directory
File should be now be gone from disk (but still in memory)
Try ^Z and check it with 'ls rmtest' ... (come back with 'fg')
 
Suspended
% ls rmtest
ls: rmtest: No such file or directory
% fg
rmtest
I'm still here, but the original file is long gone.
%

In reply to Re^2: Deleting a file after it runs? by liverpole
in thread Deleting a file after it runs? by Spidy

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.