# Having trouble modifying entry in a list

Hi, I am trying to create a small repository by entering three things as a list of string, namely the asp, sequence and description. The trouble that I am facing is that while I am manually running the first green block by manually changing the value of the integer-character in asp, things are running fine and I am able to use ReadLines[file] properly.

However, when I try to modify a previous asp by running the second green block of the code and using the modifiedasp, things go haywire and the output seems strange. By strange I mean that any new value that I add (now running the first block of code) after modifying a previous value (second block of code) gets incorporated together into a single list of strings. The output is shown in the second figure. I modified two values and therefore two new additions somehow merged with the modified values. Can anyone suggest me what I am doing wrong? Thanks !

(*Add a new entry*)

file = "C:\\Users\\Ali\\Desktop\\database.csv";
str = OpenAppend[file];

asp = StringJoin["ASP", "8"];
sequence = "CGTCAATGGCATGATCGAT";
description = "the foursome are combined to make 16some";

Catch[
Throw["The construct is already part of the list"],
Write[str, List[asp, sequence, description]]]]
Close[file];

(*Modify an existing entry*)

ind = 4;
existingEntry = data[[ind]];

modifiedasp = "ASP6";
modifiedSEQ = "CGTCGATCCGTATGGC";
modifiedDescription = "the dinucleosomes are combined to form 4some";

modifiedEntry = {modifiedasp, modifiedSEQ, modifiedDescription};
data[[ind]] = modifiedEntry;
Export[file, data, "List"];

Print["the previous entry ",
ToString @ existingEntry, " has been replaced by ",
ToString @ modifiedEntry]

(*Read the entire file and Print in Tableform*)

Print["There are ",
ToString @ Length[ReadList[file]], " entries in the database"]

• Please, post code, not images; try to keep it simple by posting a minimal example that illustrates the problems you are encountering and last, but not least, format your code properly -- more on that in the help centre. Sep 11 '15 at 10:46
• code added in the question. Thanks for the feedback! Sep 11 '15 at 10:51
• any help on the issue will be highly appreciated! Sep 11 '15 at 12:36
• The code you posted throws errors and does not generally behave as you indicated. Could you check it? You might also want to include a small sample database as well. Sep 11 '15 at 13:20
• basically first I created an empty .csv file (provided in the filename) and then I ran the first half of the code (i.e. before (Modify an existing entry) for three times by pressing shift enter on the block of code and during those three instances I manually change the integer-character from 1,2 and 3. Then I move to the second block of code i.e. after (modify an existing entry) and before (Read the entire file and Print in TableForm); I changed the ind to modify i.e. ind = 3 (its 4 in the code but I changed to 3 in my sample code) and run it once. Sep 11 '15 at 13:55

(*add a new entry*)
file = "C:\\Users\\Ali\\Desktop\\database.csv";
str = OpenAppend[file];
asp = StringJoin["ASP", "9"];
sequence = "CGTCAATGGCATGATCGAT";
description = "the foursome are combined to make 16some";

Throw["The construct is already part of the list"],
Put[{asp, sequence, description}, str]]]
Close[str];

(*modify an existing entry*)
ind = 1;
existingEntry = data[[ind]];
str = OpenWrite[file];
modifiedasp = "ASP8";
modifiedSEQ = "CGTCGATCCGTATGGC";
modifiedDescription = "the dinucleosomes are combined to form 4some";

modifiedEntry = {modifiedasp, modifiedSEQ, modifiedDescription};
data[[ind]] = modifiedEntry;
Put[#, str] & /@ data;
Close[str];

Print["the previous entry ", ToString@existingEntry, " has been replaced by ", ToString@modifiedEntry]