http://www.perlmonks.org?node_id=988261


in reply to Help Explain Behavior

Its a little more surprising than that even. Not only is the script still in memory and still running after you unlink it.

It is still on the disk also ... until the script exits ... at which point it automagically vanishes:

C:\test>copy con surprise.pl #! perl -slw use strict; unlink $0; print "still here"; print for glob $0; print "Still there also"; ^Z 1 file(s) copied. C:\test>surprise.pl still here C:\test\surprise.pl Still there also C:\test>dir surprise.pl Directory of C:\test File Not Found C:\test>

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Help Explain Behavior
by Joe_ (Beadle) on Aug 19, 2012 at 17:22 UTC

    Now that seems really strange to me. I understand that the whole script was already loaded into memory by the time the unlink happens; but shouldn't the file vanish after the unlink?

      When Perl loads the script, it retains an open filehandle to the source. The filesystem won't allow the file to be deleted until all open filehandles are closed.

      So until the script ends, the source file is in a "marked for deletion" state.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Thanks, I get it now.