免费注册 查看新帖 |

Chinaunix

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

初学请教 哈希 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-10-31 01:03 |只看该作者 |倒序浏览
大家好,看到一个帖子打印哈希二维的key,想请教下面代码高亮部分如何理解?为什么是@result,在这里表示数组吗?请大神赐教,谢谢了!

  1. my %result;
  2. $result{"a"}{"b"}=1;
  3. $result{"a"}{"c"}=1;

  4. my @a = keys <span style="background-color: Yellow;"> %{@result</span>{keys %result}};
  5. print "@a";
复制代码



论坛徽章:
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 [报告]
发表于 2016-10-31 05:56 |只看该作者
1. 有问要有回
  http://bbs.chinaunix.net/thread-4255120-1-1.html

2. 错误方法勿学
  试试
  $result{"a"}{"b"}=1;
  $result{"b"}{"c"}=1;

3. 看doc
$ perldoc perldata
NAME
    perldata - Perl data types

DESCRIPTION
  Variable names
    Perl has three built-in data types: scalars, arrays of scalars, and
    ...

    Scalar values are always named with '$', even when referring to a scalar
    that is part of an array or a hash. The '$' symbol works semantically like
    the English word "the" in that it indicates a single value is expected.

        $days               # the simple scalar value "days"
        $days[28]           # the 29th element of array @days
        $days{'Feb'}        # the 'Feb' value from hash %days
        $#days              # the last index of array @days

    Entire arrays (and slices of arrays and hashes) are denoted by '@', which
    works much as the word "these" or "those" does in English, in that it
    indicates multiple values are expected.

        @days               # ($days[0], $days[1],... $days[n])
        @days[3,4,5]        # same as ($days[3],$days[4],$days[5])
        @days{'a','c'}      # same as ($days{'a'},$days{'c'})

求职 : 软件工程师
论坛徽章:
3
程序设计版块每日发帖之星
日期:2015-10-07 06:20:00程序设计版块每日发帖之星
日期:2015-12-13 06:20:00程序设计版块每日发帖之星
日期:2016-05-05 06:20:00
3 [报告]
发表于 2016-10-31 16:35 |只看该作者
my @a = keys  %{@result{keys %result}};
print "@a";

论坛徽章:
0
4 [报告]
发表于 2016-11-04 17:02 |只看该作者
楼主什么意思?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP