免费注册 查看新帖 |

Chinaunix

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

hash结构的输出问题? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-02 19:02 |只看该作者 |倒序浏览
my %hash = (
            '10' => 'one',
            '2A' => 'two',
            '30' => 'three',
            );
(@key,@value) = each %hash;

@str=("  ","a a","FIS 0x10 s","FIS 0x2A=2","cc");
for($i=0;$i<@str;$i++)
   {if($str[$i]=~/^\s+/)
       { print "unuse"."\n"; }
    if($str[$i]=~/(FIS.*0x)((\d|\w)(\d|\w))/)
       { print $2."\n";
         if ($2=~/ foreach $key (keys %hash)/)
              { print $value (values %hash);}
        }
    else {$str[$i]="$str[$i] \n";  }
#  print $str[$i]."\n";
  }
想要通过匹配hash里面的key 10&2A来得到one&two,怎样可以实现?

现在可以输出:
unuse
10
2A
想要输出如下内容,该怎样实现呢?
one
two

论坛徽章:
0
2 [报告]
发表于 2008-12-02 21:13 |只看该作者
Using regxp + exists()
%hash = (  '10' => 'one',    '2A' => 'two',      '30' => 'three'  );
@str=("  ","a a","FIS 0x10 s","FIS 0x2A=2","cc");
for (@str) {
    if (/0x([\dA-Z]+)/ && exists $hash{$1}) {
        print "$1 = $hash{$1}\n";
    }
}

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
3 [报告]
发表于 2008-12-02 22:41 |只看该作者
my %hash = (
         '10' => 'one',
         '2A' => 'two',
        '30' => 'three',
        );
@str=("  ","a a","FIS 0x10 s","FIS 0x2A=2","cc");
map { /FIS 0x([0-9A-F]+)/ &&  exists $hash{$1} && print $hash{$1}, "\n" } @str;

论坛徽章:
0
4 [报告]
发表于 2008-12-03 11:37 |只看该作者

tthanks for help!

谢谢楼上两位!

[ 本帖最后由 qinyu2008 于 2008-12-3 11:38 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2008-12-03 15:32 |只看该作者

回复 #3 ynchnluiti 的帖子

上次好像见了用了MAP,哈哈
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP