in reply to Datafile doesn't update before being read

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.

Replies are listed 'Best First'.
Re: Re: Datafile doesn't update before being read
by ghopper (Novice) on Jun 06, 2002 at 20:18 UTC
    Something like this has to be right. I'll go check. Thanks a bunch, I'll report back!
Re: Re: Datafile doesn't update before being read
by ghopper (Novice) on Jun 06, 2002 at 20:33 UTC
    You had to be right about this (your explanation was the only one I had and very elegant, to boot), but I couldn't spot where I was reading the changed file back into the array that you read the original into. I thought (could be wrong) I had made a local copy of the @strmeta ("structured metadata") variable for purposes of the deletion bits. I still think you had to be right, but I couldn't find the exact source of the error.

    Instead I took George's advice and simply made @strmeta a global variable (er, well, I don't actually know if "global" is the right word--I didn't make a local copy), and didn't reload it after writing it to file, just used the altered @strdata array to print out the changed data. The problem went away!

    Thanks very much to everyone!

    --ghopper