f



read file in tcl

how to read or call a file in tcl ?
0
8/11/2003 8:27:30 AM
comp.lang.tcl 23428 articles. 2 followers. Post Follow

9 Replies
972 Views

Similar Articles

[PageSpeed] 5

davidw@dedasys.com (David N. Welton) wrote in message news:<873cg837s7.fsf@dedasys.com>...
> prowarcraftplayer@yahoo.com (K Zewi) writes:
> 
> > how to read or call a file in tcl ?
> 
> 'call' a file?
> 
> Reading a file can be done with the 'read' command:
> 
> set fl [open "somefile"]
> set data [read $fl]
> 
> is a simple way to do it.  You want to look at the documents for those
> commands, and maybe 'fconfigure' if you want to read a binary file.


i still can't read the file
assume that the files contain of the koordinate of the polygon
and i would like to read them to replace the 
create poly command in tcl
can i do so?
is there any tutorial on this read file method on the web
thank you!!!!
0
8/11/2003 2:45:04 PM
On 11 Aug 2003, K Zewi wrote:

> i still can't read the file
> assume that the files contain of the koordinate of the polygon
> and i would like to read them to replace the 
> create poly command in tcl
> can i do so?
> is there any tutorial on this read file method on the web
> thank you!!!!

    http://wiki.tcl.tk/open
    http://wiki.tcl.tk/read
    http://wiki.tcl.tk/close

    http://www.tcl.tk/man/tcl8.4/TclCmd/open.htm
    http://www.tcl.tk/man/tcl8.4/TclCmd/read.htm
    http://www.tcl.tk/man/tcl8.4/TclCmd/close.htm

Michael

0
michael6504 (290)
8/11/2003 2:50:53 PM
try this 

set fo [open "filename" r]
while { ![eof $fo]} {
gets $fo line

to read the content of file line by line
0
8/11/2003 3:37:36 PM
K Zewi wrote:
> 
> i still can't read the file

Show us the error. Otherwise we have to spend time guessing what you 
mean by "can't". Is it because the file doesn't exist? You don't have 
permission? You're giving the wrong name to the command? You're using 
the wrong command? You're making quoting mistakes? It's working but you 
don't realize it...........?

0
bryan1 (353)
8/11/2003 3:49:07 PM
* prowarcraftplayer@yahoo.com (K Zewi)
| i still can't open the file with these command

Please show the error message you get.

| is the "somefile" mean "C:\WINDOWS\Desktop\sample.txt"

Read about the meaning of the \-character in the TCL language, then
try any of
   "C:/WINDOWS/Desktop/sample.txt"
   "C:\\WINDOWS\\Desktop\\sample.txt"
   {C:\WINDOWS\Desktop\sample.txt}

| or is there any tutorial within these command on the internet

http://mini.net/tcl
http://www.tcl.tk/man/tcl8.4/

R'
0
ralfixx (1283)
8/11/2003 4:01:52 PM
Ralf Fassel wrote:
> * prowarcraftplayer@yahoo.com (K Zewi)
> | i still can't open the file with these command
> 
> Please show the error message you get.
> 
> | is the "somefile" mean "C:\WINDOWS\Desktop\sample.txt"
> 
> Read about the meaning of the \-character in the TCL language, then
> try any of
>    "C:/WINDOWS/Desktop/sample.txt"
>    "C:\\WINDOWS\\Desktop\\sample.txt"
>    {C:\WINDOWS\Desktop\sample.txt}
> 
> | or is there any tutorial within these command on the internet
> 
> http://mini.net/tcl
> http://www.tcl.tk/man/tcl8.4/
> 
> R'
> 

I advise you to use Tcl portable commands such as [file join ...], [pwd] 
and [file dirname [info script]] to navigate through directories. Tcl 
will do all the nasty work for you (separating character, etc.).

Charles-Christophe.

0
8/12/2003 7:17:34 AM
i've done it 
thanks a lot
pals
0
8/12/2003 7:57:34 AM
* Charles Christophe THOMART <Charles-Christophe.Thomart@axlog.fr>
| I advise you to use Tcl portable commands such as [file join ...],
| [pwd] and [file dirname [info script]] to navigate through
| directories.

Good advice in most of the times, especially when using environment
variables to derive file names.  These might have \ as directory
separators, while your add-ons use /, so the na�ve approach gives you
something like c:\Programs\foo/bar/baz.  `file join' solves all this.

However, when it comes to `well known' literal file names (which I had
the impression the OP did use), I tend to avoid `file join', as in
  set file /foo/bar/baz
  set file c:/foo/bar/baz
vs.
  set file [file join / foo bar baz]
  set file [file join c:/ foo bar baz]

Plus, in literals, I never use \ as separator in my own code ;-)
R'
0
ralfixx (1283)
8/12/2003 10:13:51 AM
prowarcraftplayer@yahoo.com (K Zewi) wrote in message news:<36940419.0308110645.7211bc88@posting.google.com>...
> davidw@dedasys.com (David N. Welton) wrote in message news:<873cg837s7.fsf@dedasys.com>...
> > prowarcraftplayer@yahoo.com (K Zewi) writes:
> > 
> > > how to read or call a file in tcl ?
> > 
> > 'call' a file?
> > 
> > Reading a file can be done with the 'read' command:
> > 
> > set fl [open "somefile"]
> > set data [read $fl]
> > 
> > is a simple way to do it.  You want to look at the documents for those
> > commands, and maybe 'fconfigure' if you want to read a binary file.
> 
> 
> i still can't read the file
> assume that the files contain of the koordinate of the polygon
> and i would like to read them to replace the 
> create poly command in tcl
> can i do so?
> is there any tutorial on this read file method on the web
> thank you!!!!



try this:
proc highlightmap { c name } {
global hcolor
$c itemconfigure $name -fill $hcolor
global t
$t delete 0 end
$t insert end $name
}



proc posts { c } {
set ftypes {{{PostScript Files} {.ps}}}
set filename [tk_getSaveFile -filetypes $ftypes]
$c postscript -file $filename.ps -width 800 -height 400
}
0
jorntk (34)
8/17/2003 4:04:09 PM
Reply: