Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input from keyboard in Tcl

Tags:

tcl

How do I give input to a Tcl script through the keyboard? Is there any thing like scanf() in C?

like image 649
srikanthM Avatar asked Dec 03 '09 20:12

srikanthM


1 Answers

The gets command is probably what you want.

set data [gets stdin]
# or
set numchars [gets stdin data]

The scan command can be used to parse the input similar to how scanf does with C. It uses the format: scan string format ?varName varName ...?

Thus, to parse an input like "5 cats" to individual variables:

set data [gets stdin]
scan $data "%d %s" myint mystring

Edit: Added more information from Colin's comment.

like image 137
RHSeeger Avatar answered Oct 18 '22 21:10

RHSeeger