且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 tcl 脚本调用 Perl 脚本

更新时间:2023-09-10 09:26:46

tl;dr: 您缺少 -e,导致您的脚本被解释为文件名.

tl;dr: You were missing -e, causing your script to be interpreted as a filename.

从 Tcl 内部运行 perl 命令:

To run a perl command from inside Tcl:

proc perl {script args} {
    exec perl -e $script {*}$args
    # or in 8.4: eval [list perl -e $script] $args
}

然后你可以这样做:

puts [perl {
    print "Hello "
    print "World\n"
}]

没错,Tcl 中的任意 perl 脚本.您甚至可以根据需要传入其他参数;通过 @ARGV 从 perl 访问.(您需要显式添加其他选项,例如 -p.)

That's right, an arbitrary perl script inside Tcl. You can even pass in other arguments as necessary; access from perl via @ARGV. (You'll need to add other options like -p explicitly.)

注意这可以传递整个脚本;您不需要将它们分开(并且可能不应该;您可以用单线做很多事情,但它们往往很难维护,而且没有技术上的理由需要它).

Note that this can pass whole scripts; you don't need to split them up (and probably shouldn't; you can do lots with one-liners but they tend to be awful to maintain and there's no technical reason to require it).