I want to use Perl to read in the version of Tcl version that the module
Tcl::pTk
is linked to. I found the following which is working fine
use strict;
use warnings;
use Tcl::pTk;
my $int = new Tcl::pTk;
$int->Eval(<<'EOS');
# pure-tcl code to create widgets (e.g. generated by some GUI builder)
text .e
## http://wiki.tcl.tk/1626#tk_version
.e insert end "tcl_version $tcl_version\n"
.e insert end "tcl_patchLevel $tcl_patchLevel\n"
.e insert end "tk_version $tk_version\n"
.e insert end "tk_patchLevel $tk_patchLevel\n"
.e insert end "tk_library $tk_library\n"
pack .e
EOS
my $e = $int->widget('.e'); # get .e entry into play
$int->MainLoop;
This displays the value in the GUI but I want to use $tcl_version in other parts of my script. In this I fail, as $tcl_version seems not to exist. I do not need the GUI part, just the values of the scalars.
The simplest thing that could possibly work should be tried:
my tcl_version = $int->Eval('info tclversion');
Alternatively and equivalently on the Tcl side:
my tcl_version = $int->Eval('set tcl_version');
All Tcl commands produce a result, so that ought to be reflected across here. Also, most of the time you are better off getting the patch-level for version reporting; the language version is just really for gross features, not anything detailed like system state reporting (e.g., you need the patch number for bug reports).
I've since found undocumented methods in Tcl::pTk, $int->tclVersion and $int->tclPatchlevel, which are equivalent to $int->Eval('info tclversion') and $int->Eval('info patchlevel') respectively.
They were already used internally in Tcl::pTk. I do not plan on removing these, but also do not know if it is a good idea to keep them in the long term or make them "public"/documented, so it may be better to stick with the existing answer's approach. (Tcl::Tk, which Tcl::pTk is based on, does not have these methods.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With