kunal
kunal

Reputation: 35

setting a variable in Tcl as value returned by perl

I am trying to use following command but it is not working:

set t1 [exec perl check.pl report.txt 5]

the perl file check.pl extracts 5 values from report.txt and returns. check.pl has return in subrountine.

t1 is empty. value is not returned and not set. Is there any way to do it?

Upvotes: 1

Views: 466

Answers (1)

ristohietal
ristohietal

Reputation: 51

The problem is probably in your check.pl, you'd want it to print the extracted values in order to have the values returned from Tcl exec:

If standard output has not been redirected then the exec command returns the standard output from the last command in the pipeline, unless “2>@1” was specified, in which case standard error is included as well. (exec manual page - Tcl Built-In Commands)

For example, in tclsh:

% set foo [exec perl -e "print 'foobar\n'"]
foobar
% puts $foo
foobar

And for further parsing the output as a Tcl list you might want to split by the newline character (if the extracted values are printed each on their own line):

% set foolist [split [exec perl -e "print 'foo\nbar\n'"] "\n"]
foo bar
% llength $foolist
2
% lindex $foolist 1
bar

Upvotes: 1

Related Questions