免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3545 | 回复: 2
打印 上一主题 下一主题

use utf8 与use English下 @ARG有何不同? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-03-01 19:20 |只看该作者 |倒序浏览
这是网上的代码,略有修改,执行后,鼠标点击节点文字,会在命令行窗口输出节点文字。
  1. #!/usr/bin/perl

  2. use strict;
  3. use warnings;
  4. use English;#有此句 不需要 my @ARG=();

  5. use Tk;
  6. use Tk::Tree;

  7. my $main = MainWindow->new(-title => "语法树" );       
  8. $main->geometry("400x600");#1368

  9. my $tree = $main->ScrlTree(
  10.   -font       => 'FixedSys 8',
  11.   -itemtype   => 'text',
  12.   -separator  => '/',
  13.   -scrollbars => "se",
  14.   -selectmode => 'single',
  15.   -browsecmd => \sub {
  16.       my ($numbers) = @ARG;
  17.       print $numbers. "\n";
  18.   }
  19. );

  20. $tree->add( "one" , -text => "one" );
  21. $tree->add( "one.111" , -text => "one.111" );
  22. $tree->add( "two" , -text => "two" );
  23. $tree->add( "two.222" , -text => "two.222" );
  24. $tree->pack();
  25. MainLoop();
复制代码


我现在想改为utf8下处理汉字,但是这时编译提示需要声明 my @ARG=(); 但执行后,点击树节点,却不能输出节点文字。
  1. #!/usr/bin/perl

  2. use strict;
  3. use warnings;
  4. use utf8 ;
  5. use Encode;
  6. use Tk;
  7. use Tk::Tree;

  8. my @ARG=();#utf8 必须

  9. my $main = MainWindow->new(-title => "语法树" );       
  10. $main->geometry("400x600");#1368

  11. my $tree = $main->ScrlTree(
  12.   -font       => 'FixedSys 8',
  13.   -itemtype   => 'text',
  14.   -separator  => '/',
  15.   -scrollbars => "se",
  16.   -selectmode => 'single',
  17.   -browsecmd => \sub {
  18.       my ($numbers) = @ARG;
  19.       print $numbers. "\n";
  20.   }
  21. );

  22. $tree->add( "one" , -text => "one" );
  23. $tree->add( "one.111" , -text => "one.111" );
  24. $tree->add( "two" , -text => "two" );
  25. $tree->add( "two.222" , -text => "two.222" );
  26. $tree->pack();
  27. MainLoop();
复制代码

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
2 [报告]
发表于 2018-03-01 22:52 |只看该作者
本帖最后由 jason680 于 2018-03-02 08:07 编辑

回复 1# hztj2005

$perldoc English

NAME
    English - use nice English (or awk) names for ugly punctuation variables

SYNOPSIS
        use English;
        use English qw( -no_match_vars ) ;  # Avoids regex performance
                                            # penalty in perl 5.16 and
                                            # earlier
        ...
        if ($ERRNO =~ /denied/) { ... }

DESCRIPTION
    This module provides aliases for the built-in variables whose names no one
    seems to like to read. Variables with side-effects which get triggered
    just by accessing them (like $0) will still be affected.

    For those variables that have an awk version, both long and short English
    alternatives are provided. For example, the $/ variable can be referred to
    either $RS or $INPUT_RECORD_SEPARATOR if you are using the English module.

    See perlvar for a complete list of these.

PERFORMANCE
...

论坛徽章:
0
3 [报告]
发表于 2018-03-02 00:20 |只看该作者
回复 2# jason680

谢谢指教!

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP