Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Help Explain Behavior

by BrowserUk (Pope)
on Aug 18, 2012 at 23:31 UTC ( #988261=note: print w/ replies, xml ) Need Help??


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?


Comment on Re: Help Explain Behavior
Download Code
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-12-26 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls