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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|