The original example uses:
open(DBA, "+< $datafile") ...
but the next 2 code examples use:
open(TMPA, "+> $tempfile") ...
Note the direction of the mode indicator - in the first
example, you are opening the file for read/write
access, or, to be specific, you are opening the file
for input, and want read/write access. In the next
examples, you are opening it for output (
and clobbering
the contents in the process), and want read/write access.
The second is not very useful: if you have already opened
it for writing, and just set it to zero length, there
is nothing to read! If you are using flock, you
want to use the first example, so that any changes made
to the file (like, say, truncating it to 0 bytes) is
made
*after* you have sucessfully flocked
the file. You could possibly use the second in cases where
you do not care about what is in the file, but merely
about whether it is locked or not (e.g. a semaphore).
-
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.