good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: -e and unlinkby Masem (Monsignor) |
on Mar 14, 2001 at 03:36 UTC ( [id://64260]=note: print w/replies, xml ) | Need Help?? |
You've basically answered most of your questions: -e does check for existence, and 'unlink' is pretty much the same as doing a unix 'rm <file>'. (Unlink will not remove directories, however). So, to 3), the line checks to see if the file is there, and deletes it if it does.
Why would you use this? Obviously, I'd not use it for data files, but I would use it for lock files which might or might not be created, using such to clean those lock files away at the end of a program. Or, if I was about to write data to a temporary file before moving the temp file in place of another, I'd make sure that tmp file wasn't there before starting. In the case of the DB transactions, maybe the transactions are written to temporary files until the transactions are completed (as such in case of program failure and a COMMIT is not given to the database), and then when COMMIT is given, the changes are now unnecessary, and thus removed. But there's a number of possible reasons why that line is often used in your program, and without further context, it's hard to speculate. Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
In Section
Seekers of Perl Wisdom
|
|