O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The scan Command

The scan command parses a string according to a format specification and assigns values to variables. It returns the number of successful conversions it made. The general form of the command is:

scan string format var ?var? ?var? ...

The format for scan is nearly the same as in the format command. There is no %u scan format. The %c scan format converts one character to its decimal value.

The scan format includes a set notation. Use square brackets to delimit a set of characters. The set matches one or more characters that are copied into the variable. A dash is used to specify a range. The following scans a field of all lowercase letters.

scan abcABC {%[a-z]}result
=> 1
set result
=> abc
					

If the first character in the set ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required