> I'm trying to implement a loop in a Tcl interpreter from Perl 
> code but I'm
> finding some problems (maybe related with my un-expertise in 
> TCL :). For
> example, I'm trying to implement this simple TCL loop:
> 
> foreach i {1 2 3} {
>    puts $i
> }
> 
> I've tried (in Perl):
> 
> use Tcl;
> $i = new Tcl;
> $i->Eval('"foreach i {1 2 3} {');
> $i->Eval(' puts $i');
> $i->Eval('}');
> 
> but the result is:
> 
> tornado:~# perl /tmp/foo
> missing close-brace at /tmp/kk line 3.

This is true for all interpreters (not just Tcl/Tk -- also Perl, Python, so
on) - you "eval" only complete chunks of code, and not interrupted at
arbitrary place.



> 
> Of course, the following works fine in this case:
> 
> use Tcl;
> $i = new Tcl;
> $i->Eval('foreach i {1 2 3} { puts $i }');
> 
> but this solution only is fine for one-command loops.

Once again, Tcl::Tk interpreter is less restrictive: in AUTOLOADs previously
unknown foreach

D:\>perl -MTcl::Tk -we "$i=new Tcl::Tk;$i->foreach('i j',[1,2,3,4],'puts
$i$j')"
12
34

D:\>perl -MTcl::Tk -we "$i=new Tcl::Tk;$i->foreach('i',[1,2,3],'puts $i')"
1
2
3

D:\>perl -MTcl::Tk -we "$i=new Tcl::Tk;$i->foreach('i j',[1,2,3,4],'puts
$i$j')"
12
34

D:\>perl -MTcl::Tk -we "$i=new Tcl::Tk;$i->foreach('i j',[1,2,3,4],sub
{print qq/I am here/})"
I am hereI am here


> 
> How can I implemented a TCL loop in general using Perl Tcl module?

it is possible...

However, I was thinking about doing something more general: some kid of Tcl
sequence, and may it will be required for 'snit' multiwidget support in
Tcl::Tk.

Vadim.

Reply via email to