develooper Front page | perl.tcltk | Postings from January 2011

bind some said tcl to perl - all at once

Thread Next
From:
Konovalov, Vadim ** CTR **
Date:
January 15, 2011 13:36
Subject:
bind some said tcl to perl - all at once
Message ID:
35BF8D9716175C43BB9D67CA60CC345E274A0E19@FRMRSSXCHMBSC2.dc-m.alcatel-lucent.com
Hi Tcl.pm etc developers,
I need some advice.

In my everyday programming, I often use a subroutine that helps me to bind a number of tcl subs with perl by call to CreateCommand, namely this part of code:

sub Tcl::Tk::bind_ptcl {
    my $int = shift;
    no strict 'refs';
    for my $subname (keys %::ptcl::) {
	$int->CreateCommand("ptcl_$subname",\&{"ptcl::$subname"});
    }
}

this allows me to create a number of subroutines in Perl in ptcl:: namespace that are automatically get binded to Tcl/tk all at once

sub ptcl::sub1 {
  print "hi, I am sub1!\n";
}

and then write in pure-tcl GUI code
$interp->Eval <<'EOS';
button .b -text {button 1} -command ptcl_sub1
EOS

or, if pure-Tcl is not preferable, the old way:
$frame->Button(-text=>'button1', -command=>'ptcl_sub1');

so this works well (actually I have same approach for binding variable names)

I wonder, is it reasonable for this approach to be "standartized" and included to, say, Tcl.pm module?

Maybe with a slightly different interface.

For example - all Tcl names from some predefined Tcl namespace could be bound to perl subroutines all at once.
I find this very helpful.

Thanks in advance for your ideas,
Vadim.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About