[GRASS5] New submission instructions for tcl/tk

Glynn Clements glynn at gclements.plus.com
Tue May 2 19:05:03 EDT 2006


Cedric Shock wrote:

> I added SUBMITTING_TCLTK to the grass6 directory, in there along with 
> SUBMITTING_SCRIPTS and SUBMITTING.  I tried to shove as much knowledge and 
> wisdom into it as I could think of, remember, and copy and paste in half an 
> hour.  I would greatly appreciate any expansion, addition, or correction.

One minor point:

    Regular expressions:
    Very slow:
        regex "x([0-9]+).*not" $string trash number

Apart from being slow, the example is also incorrect; Within
double-quoted strings, Tcl will subject [...] to command substitution. 
You need to either use backslashes or use braces instead of quotes.

Similarly, both backslash and the dollar sign are both Tcl syntax and
regexp syntax. Consequently, regexps should normally be enclosed in
braces rather than quotes to prevent Tcl from accidentally
interpreting a regexp metacharacter as a Tcl metacharacter.

A more significant point, which is often overlooked, is to use the Tcl
list functions (list, lappend etc) for manipulating lists; e.g. use:

	set vals [list $foo $bar]

rather than:

	set vals "$foo $bar"

The former will always create a list with two elements, adding braces
if necessary, while the latter will split $foo and $bar into multiple
elements if they contain spaces.

A related issue is to remember that command lines (as used by exec and
open "|...") are treated as lists; i.e. exec behaves like execl(),
spawnl() etc, not like system().

Overlooking either of these points is likely to result in code which
fails when an command argument contains a space.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list