* Matthias Keppler <
make....@gmail.com>
| # delete all items of cTARGET wihtout destroy the canvas
| foreach cITEM [$cTARGET find withtag all] { eval $cTARGET delete $cITEM }
Instead of the foreach loop, why not simply
$cTARGET delete all?
Or at least, if you insist on the loop:
foreach cITEM [$cTARGET find withtag all] { $cTARGET delete $cITEM }
The canvas subcommand 'find' gives you single items, so you can (should)
delete them as single items. You don't need 'eval' to expand anything here.
A further note about 'eval': consider what
eval $cTARGET delete $cITEM
does: in simple terms, it expands the values of $cTARGET and $cITEM and
then calls the TCL parser again on the result. *All* functionality of
the TCL parser is available in that second round.
Now imagine someone has created the canvas with name
.c;[exec rm -rf $::env(HOME)]
Then you pass the following command to the TCL parser:
.c;[exec rm -rf $::env(HOME)] delete 1
Question #1: what will this do?
Yes that's a silly name for a canvas, but it is (a) possible to do, and
(b) serves only as example that when you use eval, you completely rely
on nothing evil sitting in each of the variables.
=> You don't need eval.
=> If you think you do, consider using {*} first.
=> If you don't have {*}, upgrade your TCL :-)
Check
http://wiki.tcl.tk/14069 and the articles it refers to.
HTH
R'