Re: tcl command "type"
- From: Bryan Oakley <oakley@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 31 Dec 2005 19:14:12 GMT
suchodj@xxxxxxxxxx wrote:
Hello i am under windows xp family and Tcl/Tk 8.4
in the book "SAMS teach yourself Tcl/Tk" isbn 0-672-31749-4 page 154 listing 9.6 i find the following code
source myfile.tcl type myfile.tcl
when i code it i obtain the following error
invalid command name "type"
in the man pages "http://www.tcl.tk/man/tcl8.4/TclCmd/" if cannot find this command.
my question is: if after having source any myfile.tcl i want to print it in the console is there a command to do it ?
No, there is not. There are a myriad of ways to do this, though I'm puzzled why you would need to. You can simply open the file up with your editor of choice.
If you really want the contents dumped to the screen, you can read it in and print it out. Perhaps the SAMS book has you write a procedure to do that, and that is what the "type" command is.
For example, you can enter the following interactively or put it in myfile.tcl:
proc type {filename} {
if {![file exists $filename]} {
return -code error "file \"$filename\" doesn't exist"
}
if {![file readable $filename]} {
return -code error "file \"$filename\" isn't readable"
}
set f [open $filename r]
set data [read $f]
close $f
return $data
}If you are running interactively, doing 'type myfile.tcl' at the prompt (without the quotes) will show the contents of the file. If you put the 'type myfile.tcl' command in a script you will need to explicitly print out the output from the type command:
puts [type myfile.tcl]
-or-
set result [type myfile.tcl]
puts $resultThe reason is that when running interactively, tclsh and wish will automatically print out the result of a command when it is run as a convenience.
.
- Follow-Ups:
- Re: tcl command "type"
- From: suchodj
- Re: tcl command "type"
- References:
- tcl command "type"
- From: suchodj
- tcl command "type"
- Prev by Date: tcl command "type"
- Next by Date: Re: how to run tkinspect
- Previous by thread: tcl command "type"
- Next by thread: Re: tcl command "type"
- Index(es):
Relevant Pages
|