我有Perl和Windows的编码问题.在运行Perl的Windows 7(草莓5.16)和简单的TK GUI上,我需要打开文件和/或访问名称/路径中包含非英文字符的目录.对于打开文件我已经提出这个解决方案似乎工作正常:
#!/usr/bin/perl -w
use strict;
use warnings;
use Win32::Unicode::File;
use Encode;
use Tk;
my $mw = Tk::MainWindow->new;
my $tissue_but = $mw->Button(
-text => 'Open file',
-command => [ \&select_unicode_file ],
);
$tissue_but->grid( -row => 3, -column => 1 );
Tk::MainLoop();
sub select_unicode_file{
my $types = [ ['Txt', '.txt'],
['All Files', '*'],];
my $input_file= $mw->getOpenFile(-filetypes => $types);
my $fh = Win32::Unicode::File->new;
if ($fh->open('<', $input_file)){
while (my $line = $fh->readline()){
print "\n$line\n";
}
close $fh;
}
else{
print "Couldn't open …Run Code Online (Sandbox Code Playgroud) 我想使用Perl来读取模块Tcl::pTk
链接到的Tcl版本
.我发现以下哪个工作正常
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;
Run Code Online (Sandbox Code Playgroud)
这会在GUI中显示值,但我想$tcl_version在脚本的其他部分使用.在这我失败了,$tcl_version似乎不存在.我不需要GUI部分,只需要标量的值.