Version 8 of Ways to execute Perl programs from Tcl

Updated 2001-10-18 21:20:20

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.]


It's quick work in Tcl to code a

    proc perl_interpret scripte {
        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 {
              if { [ regexp {^-+\S+$} $arg ] } {
                 set perl_opts [ concat $arg $perl_opts ]
              } else {
                 lappend perl_code $arg
              }


























Tclperl is quite nice. So is the Perl widget, although in a much different way.