For Programmers: Free Programming Magazines  


Home > Archive > Tcl > June 2007 > Re: File r+ and w+ difference









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: File r+ and w+ difference
Ralf Fassel

2007-06-28, 4:18 am

* Chendu <pjsenthil@gmail.com>
| proc Num {} {
| if { [file exists [pwd]/temp/idmt] } {
| set idfile [open "[pwd]/temp/id_cnt" r+ 0600]

You check for one file but open another? Better skip the 'file exist'
and simply try to open the file in read-only mode. If the open
succeeds, the file is already there.

| } else {
| file mkdir temp
| set idfile [open "[pwd]/temp/idmt" r+ 0600]
| puts $id 001

Not sure whether you would need to rewind before reading the file
after a write.

| set id [read $idfile]

As Gerald pointed out in another message, most likely you need 'read
-nonewline' here in order to treat 'id' as an integer. Also you need
to deal with the possibility that 'id' is non-numeric after the read
(like the empty string in your case).

| s $idfile 0 start

Rather than sing around I would simply reopen the file in write
mode for the update.

| close $idt

Variable idt has never been set.

HTH
R'
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com