Are you by any chance reading the changed file back into the array that you read the original into?

My theory is this: You have an array that holds the original file data; you then create some array which you modify via the splice. You then output the keys that you want to keep. You then read in the now modified file into the original array that you started with via some method that is not clearing the array before you read into it.

read from file to @orig @orig = [ 1 2 3 4 A B C ] @mod_copy = [ 1 2 3 4 A B C ] splice @mod_copy @mod_copy = [ 1 2 3 4 A C ] print join of @mod_copy to file file is now ( 1 2 3 4 A C ) read from file to @orig by indexing @orig = [ 1 2 3 4 A C C ]
Notice how the last C is leftover? The reason I suspect this is because the results you report look like the original list overwritten with the new list, but not erasing the originals that are left beyond the end of the list.

In reply to Re: Datafile doesn't update before being read by Sifmole
in thread Datafile doesn't update before being read by ghopper

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.