Chinaunix

标题: use utf8 与use English下 @ARG有何不同? [打印本页]

作者: hztj2005    时间: 2018-03-01 19:20
标题: use utf8 与use English下 @ARG有何不同?
这是网上的代码,略有修改,执行后,鼠标点击节点文字,会在命令行窗口输出节点文字。
  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();
复制代码

作者: jason680    时间: 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
...

作者: hztj2005    时间: 2018-03-02 00:20
回复 2# jason680

谢谢指教!






欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2