Actually that was a typo,I do have the "$" infront,what actually does unlink do?does it really delete the files in the directory?basically my script generates some "txt" files in between,so I am trying to delete them when I rerun the script,but seems like they are not getting deleted.
| [reply] |
It's called 'unlink' because it removes the directory entry (file name), which can be considered a 'link' to the actual file (the data).
Note that (on Unix) multiple file names (hard or symbolic links) can point to the same file. The unlink system call (or the user command of the same name) deletes the name, the file itself is only deleted if that name was the last (hard) link/reference to the file.
| [reply] [d/l] |
| [reply] |
"what actually does unlink do?"
The post by Eliya is very close to the mark. Since we are talking about "unlink", another point is of interest especially if you are ever writing a program that updates software.
This discussion applies to Windows also! A "file" is a collection of data bits on the disk. The directory has a "human readable name" that "points" to those bits. The "open" translates the "human readable name" into a data structure that the file system uses to access the data bits, this is the "filehandle". Once a file is "open", the "name" doesn't matter <- this is important. If the file is open, you can change the name or even delete the name without affecting the data bits!
Its been a while since I wrote a software updater for a continuously running system, but basically the idea is to copy all the important stuff onto the target. Say x.dll would get a temporary name of x_temp.dll. Then, x.dll gets "unlinked". Everyone who has this file "open" and is using it, continues to use it even though it has no "name". Then, x_temp.dll is renamed to x.dll and new requests for "x.dll" will get the updated file. The actual "old x.dll" file bits will get "deleted" when then are no longer in use (everyone using it does a close). "Delete" in this case means to mark that area of the disk as available for other use.
From say the Windows command line, you might see something like >del X, unable to delete file X, file is in use. However the Perl unlink 'X' command will succeed. the above was just to round out discussion of "what does unlink" do - and it is a bit different than command line "delete". Sounds to me like the most likely thing in OP's scenario is wrong permissions on the directory. Unlink of a read only file is completely ok. Anyway, Perl "unlink" does what a UNIX person would expect, even on Windows.
| [reply] |
| [reply] |