Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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 reply to Re: -e and unlink by Masem
in thread -e and unlink by DeusVult

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-28 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found