哈希散列的智能匹配运算符 [英] smart match operator for hash of hash

查看:116
本文介绍了哈希散列的智能匹配运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

  $ line = 

群(A,B):A(T)M(S);
$ reg =集群;
my($ cluster,$ characters)= split(/:/,$ line);
$ HoH {$ cluster} = {split / [()] + /,$ characters};
foreach $ value(keys%HoH){
foreach $ characters(keys%{$ HoH {$ cluster}}){
print$ value:$ characters \\\
if / $ reg / ~~%HoH;


$ / code $ / pre

现在输出:

集群(A,B):A

集群(A,B):M

此代码对此示例数据可以正常工作,但不会与真实数据!我的数据比较复杂,但结构相同我想知道是否有其他方法可以做到这一点

解决方案

SmartMatch是目前复杂,笨拙和令人惊讶。不要使用它,至少现在不用。 Perl的主要开发人员正在谈论,要么大大简化它,要么完全删除它。无论哪种方式,它不会做你将来要做的事情,所以现在不要依赖它。



更明确地说明什么无论如何,你想要的更好。


I want to match keys of a hash of hash with regexp .

$line=" Cluster(A,B):A(T) M(S)";
$reg="Cluster";
my ( $cluster, $characters ) = split (/:/,$line);
$HoH{$cluster}={split /[( )]+/,$characters } ;
foreach $value(keys %HoH){
    foreach $characters (keys %{$HoH{$cluster}}){
        print "$value:$characters\n" if    /$reg/ ~~ %HoH;
    }
}

now Output is :

Cluster(A,B):A

Cluster(A,B):M

This code is works fine with this sample data,but not with real data!! my data is more complicated but the structure is the same I was wondering if there is some other ways to do this

解决方案

SmartMatch is currently complicated, unwieldy and surprising. Don't use it, at least not now. There's talk by the main developers of perl to either greatly simplify it or remove it completely. Either way it won't do what you're asking it to do in the future, so don't rely on it doing that now.

Being more explicit about what you want is better anyway.

这篇关于哈希散列的智能匹配运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆