# This example has a couple of roles: # 1. I use generalizations of it in real work. A sample # usage is # source other_tcl # # set a 13 # set b 79 # # puts [perl_interpret { # $result = [set a] + [set b]; # print "The sum is ", $result, ".\n"; # }] # Roughly, anything within the {} can be normal Perl code, except that # unescaped []-s are available for Tcl-side command substitution. # # In practice, I usually have slightly more involved proc definitions, # which implement various kinds of introspection, logging, invocation # of processors other than Perl, improved exception-handling, ... # # Reasons to use other languages: Perl's REs, Python's mathematics # extension, ... # 2. It's a minimal example of significant use of uplevel and subst. # [Sometime I should show RE uses of subst, and the do-while I've # published somewhere.] proc perl_interpret script { return [exec perl << [uplevel [list subst -novariables -noback $script]]] }