I bet that's because perl opens the file, reads it, closes it and then runs the code.

$ cat > hw.pl #!/usr/bin/perl print "Hello, World!\n"; sleep 5; print "exiting...\n"; $ chmod 755 !$ chmod 755 hw.pl $ strace -o abc -tt -ff -s 500 !$ strace -o abc -tt -ff -s 500 hw.pl $ _ (stripped strace output) 21:33:16.679617 open("/home/hue/lang/perl/hw.pl", O_RDONLY|O_LARGEFILE +) = 3 21:33:16.681557 read(3, "#!/usr/bin/perl\nprint \"Hello, World!\\n\";\ +nsleep 5;\nprint \"exiting...\\n\";\n", 4096) = 72 21:33:16.681985 read(3, "", 4096) = 0 21:33:16.682080 close(3) = 0 21:33:16.682336 write(1, "Hello, World!\n", 14) = 14 21:33:16.683833 nanosleep({5, 0}, {5, 0}) = 0 21:33:21.663964 write(1, "exiting...\n", 11) = 11

Doing an lsof -n|grep hw shows that no process (except hw.pl itself) has the file opened, so when one unlinks it, the operation performs immediatly.

--
David Serrano


In reply to Re^5: Deleting a file after it runs? by Hue-Bond
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.