In general you don't! The whole idea of perl/Tk is that you are programming in perl not Tcl. To glean the possible advantages of doing this you might want to read the opinions of Tom Christiansen (a definite perl proponent) at:
ftp://mox.perl.com/pub/perl/versus/tcl
It is nevertheless worth noting that you might still have access to a complete Tcl script from perl via the perl system, or `` (backtick), or even exec mechanisms. Just be careful with I/O waits and return values if you try one of these approaches. Further suggestions may be found in the various perlipc files at:
ftp://ftp.perl.com/perl/info/everything_to_know/
A more satisfactory wish-like behavior can be embedded in perl by
making appropriate modifications to
Dov Grobgeld's perl script that uses
sockets for perl<->wish communication:
#!/usr/local/bin/perl
#####################################################################
# An example of calling wish as a subshell under Perl and
# interactively communicating with it through sockets.
#
# The script is directly based on Gustaf Neumann's perlwafe script.
#
# Dov Grobgeld dov@menora.weizmann.ac.il
# 1993-05-17
#####################################################################
$wishbin = "/usr/local/bin/wish";
die "socketpair unsuccessful: $!!\n" unless socketpair(W0,WISH,1,1,0);
if ($pid=fork) {
select(WISH); $| = 1;
select(STDOUT);
# Create some TCL procedures
print WISH 'proc echo {s} {puts stdout $s; flush stdout}',"\n";
# Create the widgets
print WISH <<TCL;
# This is a comment "inside" wish
frame .f -relief raised -border 1 -bg green
pack append . .f {top fill expand}
button .f.button-pressme -text "Press me" -command {
echo "That's nice."
}
button .f.button-quit -text quit -command {
echo "quit"
}
pack append .f .f.button-pressme {top fill expand} \\
.f.button-quit {top expand}
TCL
# Here is the main loop which receives and sends commands
# to wish.
while (<WISH>) {
chop;
print "Wish sais: <$_>\n";
if (/^quit/) { print WISH "destroy .\n"; last; }
}
wait;
} elsif (defined $pid) {
open(STDOUT, ">&W0");
open(STDIN, ">&W0");
close(W0);
select(STDOUT); $| = 1;
exec "$wishbin --";
} else {
die "fork error: $!\n";
}
Ilya Zakharevich
<ilya@math.ohio-state.edu>
has a "ptcl.h" header file for the construction of tcl bindings from
pTk (there are limitations to this approach). It was posted to the mailing
list archive at:
http://sun20.ccd.bnl.gov/~ptk/archive/ptk.1995.11/0057.html
If you absolutely must pass large amounts of pre-parsed data between Tcl and
perl then perhaps you should look into Malcolm Beattie's Tcl/Tk
extensions to Perl instead. Those modules are distrubuted at
CPAN sites. As mentioned above running Tcl/Tk/perl is
incompatible with running perl/Tk.
Previous | Return to table of contents | Next