Re: tcl command "type"
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: tcl command "type"

From: <suchodj@wanadoo.fr>
Date: Sat Dec 31 2005 - 20:29:32 CET

thank you for helping.
my idea was the following : i am coding a little application and
sourcing several files in a sort of main file. In order to check if
the files were correctly sourced i thaught of dumping them ???
Anyway with your code I will be able to make my dumping.
Sorry if my checking solution is "exageratly newbee-ish".
friendly
jerome

On Sat, 31 Dec 2005 19:14:12 GMT, Bryan Oakley
<oakley@bardo.clearlight.com> wrote:

>suchodj@wanadoo.fr 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 $result
>
>The 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.
>
>
Received on Tue Jan 3 03:09:59 2006