免费注册 查看新帖 |

Chinaunix

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

判断HASH VALUE的未定义值出错(已解决) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-03-17 10:42 |只看该作者 |正序浏览
本帖最后由 jjqing 于 2014-03-17 13:33 编辑

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Smart::Comments '###';

my (%hash,$result);

%hash = (
    cluster_name => undef,
    column_name => 'OBJ#',
    column_position => '1',
    extents => '102',
    index_name => 'I_IDL_UB11',
    index_size => 2097152,
    index_tablespace_name => 'SYSTEM',
    index_type => 'NORMAL',
    iot_type => undef,
    nested => 'NO',
    owner => 'SYS',
    table_name => 'IDL_UB1$',
    table_size => 260046848,
    tablespace_name => 'SYSTEM',
    temporary => 'N'
);
### %hash
push ( @$result, { %hash } );
### $result

foreach my $a ( @{ $result } ) {
    my $hash;
    ### $a
    if ( defined $a->{cluster_name} ) { #此处为何老是报"Use of uninitialized value"
        $hash->{table_type} = 'CLUSTER';
    }
    elsif ( defined $a->{iot_type} ) {
        $hash->{table_type} = $a->{iot_type};
    }
    elsif ( $a->{nested} ne "NO" ) {
        $hash->{table_type} = '嵌套表';
    }
    elsif ( $a->{temporary} ne "N") {
        $hash->{table_type} = "临时表";
    }
    elsif ( $a->{partitioned} eq "YES") {
        $hash->{table_type} = "分区表";
    }
    else {
        $hash->{table_type} = "堆表";
    }
}

=d 以下是运行屏幕显示
[teamsun@TeamWorks tmp]$ perl 8
### $a: {
###       cluster_name => undef,
###       column_name => 'OBJ#',
###       column_position => '1',
###       extents => '102',
###       index_name => 'I_IDL_UB11',
###       index_size => 2097152,
###       index_tablespace_name => 'SYSTEM',
###       index_type => 'NORMAL',
###       iot_type => undef,
###       nested => 'NO',
###       owner => 'SYS',
###       table_name => 'IDL_UB1$',
###       table_size => 260046848,
###       tablespace_name => 'SYSTEM',
###       temporary => 'N'
###     }
Use of uninitialized value in string eq at 1 line 35 (#1)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
    To suppress this warning assign a defined value to your variables.
    To help you figure out what was undefined, perl tells you what operation
    you used the undefined value in.  Note, however, that perl optimizes your
    program and the operation displayed in the warning may not necessarily
    appear literally in your program.  For example, "that $foo" is
    usually optimized into "that " . $foo, and the warning will refer to
    the concatenation (.) operator, even though there is no . in your
    program.
=cut

请问各位,为什么对这个HASH VALUE判断老是出错呢?谢谢!

论坛徽章:
0
4 [报告]
发表于 2014-03-17 13:23 |只看该作者
很感谢,原来就是因为%hash里面没有'partitioned‘这个KEY,所以才导致这段报错,现在已经修改,使%hash包含了partition,运行已经不报错了。

谢谢!

论坛徽章:
0
3 [报告]
发表于 2014-03-17 13:12 |只看该作者
本帖最后由 jjqing 于 2014-03-17 13:24 编辑

回复 2# q1208c

不好意思,%hash里面没有partitioned这个KEY,所以测试脚本改成如下,我的PERL版本是:This is perl, v5.8.9 built for x86_64-linux
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use diagnostics;
  5. use Smart::Comments '###';

  6. my (%hash,$result);

  7. %hash = (
  8.     cluster_name => undef,
  9.     column_name => 'OBJ#',
  10.     column_position => '1',
  11.     extents => '102',
  12.     index_name => 'I_IDL_UB11',
  13.     index_size => 2097152,
  14.     index_tablespace_name => 'SYSTEM',
  15.     index_type => 'NORMAL',
  16.     iot_type => undef,
  17.     nested => 'NO',
  18.     owner => 'SYS',
  19.     table_name => 'IDL_UB1,
  20.     table_size => 260046848,
  21.     tablespace_name => 'SYSTEM',
  22.     temporary => 'N'
  23. );

  24. ### %hash
  25. push ( @$result, { %hash } );
  26. ### $result


  27. foreach my $a ( @{ $result } ) {
  28.     my $hash;
  29.     ### $a
  30.     if ( defined $a->{cluster_name} ) {
  31.         $hash->{table_type} = 'CLUSTER';
  32.     }
  33.     elsif ( defined $a->{iot_type} ) {
  34.         $hash->{table_type} = $a->{iot_type};
  35.     }
  36.     elsif ( $a->{nested} ne "NO" ) {
  37.         $hash->{table_type} = '嵌套表';
  38.     }
  39.     elsif ( $a->{temporary} ne "N") {
  40.         $hash->{table_type} = "临时表";
  41.     }
  42.     else {
  43.         $hash->{table_type} = "堆表";
  44.     }

  45. }
复制代码

论坛徽章:
33
荣誉会员
日期:2011-11-23 16:44:17天秤座
日期:2014-08-26 16:18:20天秤座
日期:2014-08-29 10:12:18丑牛
日期:2014-08-29 16:06:45丑牛
日期:2014-09-03 10:28:58射手座
日期:2014-09-03 16:01:17寅虎
日期:2014-09-11 14:24:21天蝎座
日期:2014-09-17 08:33:55IT运维版块每日发帖之星
日期:2016-04-17 06:23:27操作系统版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-24 06:20:0015-16赛季CBA联赛之天津
日期:2016-05-06 12:46:59
2 [报告]
发表于 2014-03-17 11:49 |只看该作者
本帖最后由 q1208c 于 2014-03-17 11:50 编辑
  1.    elsif ( $a->{partitioned} eq "YES") {
  2.         $hash1->{table_type} = "分区表";
复制代码
我这里是这段报错.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP