免费注册 查看新帖 |

Chinaunix

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

Something interesting when learning Hash___Reserved as private thread. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-23 17:27 |只看该作者 |倒序浏览
此贴只是用于记录一些自己觉得有趣的东西,有兴趣的朋友可以仁者见仁。
=============================================
use 5.01;
use strict;
use warnings;

my @listH = ("foo", 35, "foo2", 35, "bar", 0, 2.5, "hello", "betty", "bye");
say "The list is: @listH";
# One key without value defined in the hash.
# It's same with following:
# my %testHash = ("foo"=> 35, "foo2"=> 35, "bar"=> undef, 2.5=> "hello", "betty"=> "bye");
my %testHash = ("foo"=> 35, "foo2"=> 35, "bar"=> , 2.5=> "hello", "betty"=> "bye",);

my @str = %testHash;
my %testHashRev = reverse %testHash;
my @str1 = %testHashRev;
say "\n\@str is: @str";
say "After reversed the hash: @str1";


Output:
============================================
The list is: foo 35 foo2 35 bar 0 2.5 hello betty bye
Odd number of elements in hash assignment at Y:\PerlT\ex13.pl line 11.
Use of uninitialized value $some_hash{"bye"} in list assignment at Y:\PerlT\ex13.pl line 14.
Use of uninitialized value $str[3] in join or string at Y:\PerlT\ex13.pl line 16.

@str is: bar 2.5 bye  hello betty foo 35 foo2 35
After reversed the hash:  bye 35 foo betty hello 2.5 bar

[ 本帖最后由 bequan 于 2009-12-23 17:33 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-12-23 21:21 |只看该作者
楼主 给我们讲讲
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP