writecase and ~

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
Anne
Posts: 104
Joined: January 11th, 2012, 12:55 am

writecase and ~

Post by Anne »

I was just about to use the writecase() function to update data in an external dictionary when I discovered something curious. Cut'n'pasted from the help file:

"If the case identified by var-list already exists, the writecase function will overwrite the existing case if no records in the case have changed length. If any record in the case has changed length each record in the case will be marked with a tilda, ‘~’, in the first position of the record and entire case will be appended to the end of the associated file."

why the tildas and the extra line in the data file? and is there a clever way to process them?

(I was going to update addresses in my external dictionary, and of course it should be expected that the record could change length - if the address field was the last one in the record. Fixed this by adding another field to the record, but I'm still curious why CSPro works this way

Anne
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: writecase and ~

Post by Gregory Martin »

Say, for example, that you have a large data file that is 50 megabytes and that, using the writecase command, you modify the first case in the data file, adding a record to what was previously there so that more space is needed for this case. Writecase could do two things:

1) Rewrite this case, but that would require rewriting the whole 50 megabytes to the disk. This would be a costly procedure.

2) Mark the first case as unused with the tildes and then append it to the end of the data file. This is not a costly operation, as it involves only inserting a tilde at each line of the old case and then writing the modified case at the end.

For an application that executes a lot of writecases, this second behavior is essential.

All of the CSPro programs and tools automatically remove tildes when processing the data file, so the presence of a tilde in a data file will not affect your programs adversely.

You'll also note that, while CSPro allows you to use almost any character as a record type, it won't allow you to use a tilde as a record type because it's reserved for this deleted-record function.

Finally, before distributing a CSPro data set publicly, you would probably want to get rid of all of the deleted records. One easy way to do this is to create a blank batch application, passing the data file as the input file, and your output file will be a data file with the deleted records removed.
Post Reply