You seem to be just overwriting your original file. That's not my idea of "duplicating a file". If you just happen to run the script twice, it'll append "Code1" twice. That's normal, I would think.

You're really going through a lot of trouble to copy the contents of an array, where a simple

@dataWrite = @dataRead;
would do.

Nowhere do you actually look at what @dataRead contains, after you modify @dataWrite. How would you know it changed? It didn't, I'm sure.

Oh, and this:

open(fileOUT,">../Rules1.txt") or dienice("Can't open counter.txt: $!" +);; flock(fileOUT,2); seek(fileOUT,0,0);
is a recipe for disaster: first you open the file for writing, clearing it in the process, and then you try to lock it. Too late. You can try replacing ">" with ">>", and add
truncate fileOUT, 0;
at the bottom. It might work, it surely would on some platforms.

In reply to Re: file duplication error by bart
in thread file duplication error by Roy.Amitabh

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.