There are several ways to execute Perl programs from Tcl applications. Most succinct is simply to apply Tcl's powerful exec in a command such as
exec my_program.pl
[Explain open, and other IPC, more generally.]
See also Concepts of Architectural Design for Tcl Applications and Inventory of IPC methods.
It's quick work in Tcl to code a
proc perl_interpret script {
return [exec perl << [uplevel [list subst -novariables -noback $script]]]
}which allows one to write
set a 13
set b 79
puts [perl_interpret {
$result = [set a] + [set b];
print "The sum is ", $result, ".\n";
}]Phil Ehrens offers a slightly more elaborate version:
proc perl { args } {
set perl_opts -e
foreach arg $args {
# pick off things that look like options
# to pass to perl
if { [ regexp {^-+\S+$} $arg ] } {
set perl_opts [ concat $arg $perl_opts ]
} else {
# and the rest is the code and the file args
lappend perl_code $arg
}
}
# this is the debugging code ;^)
puts stderr "perl $perl_opts $perl_code"
catch { eval exec perl $perl_opts $perl_code } result
return $result
}An example usage of this is
perl "print \"foo!\n\"; print \"bar\""
Tclperl is quite nice. So is the Perl widget, although in a much different way.
Inline::Tcl [L1 ]. And module Tcl [L2 ].
More recent version of Perl modules to access Tcl/Tk and vice versa is at [L3 ], allows invoking of perl scripts as [::perl::Eval {print "hello, I am Perl"}] VK