Re: File r+ and w+ difference
- From: Ralf Fassel <ralfixx@xxxxxx>
- Date: Thu, 28 Jun 2007 10:07:00 +0200
* Chendu <pjsenthil@xxxxxxxxx>
| 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).
| seek $idfile 0 start
Rather than seeking around I would simply reopen the file in write
mode for the update.
| close $idt
Variable idt has never been set.
HTH
R'
.
- References:
- File r+ and w+ difference
- From: Chendu
- File r+ and w+ difference
- Prev by Date: Re: question lex+yacc -> tcl parser
- Next by Date: Re: Toggle image state
- Previous by thread: Re: File r+ and w+ difference
- Next by thread: Re: File r+ and w+ difference
- Index(es):