Reputation: 259
I have a variable defined in a perl script.
How to access that same variable with the same value as defined in a tcl script which is present in the same directory as where the perl script is present
Upvotes: 0
Views: 1629
Reputation: 137557
It's very hard to know the best way to answer this without knowing the exact relationship of the Perl and Tcl programs to each other. It might be that the best way to pass a copy of the value is as an argument to the call of the other script (that's trivial in both languages) or as an environment variable. Or maybe you could store the value in a shared file; storing it in a database (e.g., in SQLite) is really just a grown-up version of this. Or you could go to quite a bit of effort and graft the two languages together so that it's really a single shared value that both languages can see at the same time. (That takes a lot more effort.)
The two easy ways are below; if they look pretty similar to you, that's because it's the same pattern in reverse.
On the Perl side:
my $theResult = `tclsh script.tcl "$theArgument"`;
On the Tcl side (in script.tcl):
set theArgument [lindex $argv 0]
# .... process ....
puts $theResult
On the Tcl side:
set theResult [exec perl script.pl $theArgument]
On the Perl side (in script.pl):
my $theArgument = $ARGV[0];
# .... process ....
print "$result\n";
Upvotes: 2
Reputation: 3844
You could write it out to a config file in the perl script and then have the tcl script read the value in from that config file.
Upvotes: 2