如何通过值(而非键)比较2个数组的哈希值 [英] How to compare 2 hashes of arrays by values(not keys)

查看:101
本文介绍了如何通过值(而非键)比较2个数组的哈希值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的数组上有哈希值,例如,

%h1 =(''''=> [''abc'',' 'def''],

''b''=> [''ghi'',''jkl''],

''c''= > [''hop'',''uio'']

);


%h2 =(''a''=> [ ''abc'',''def''],

''b''=> [''wert'',''wer'']);

然后,我如何比较2个哈希值(基于值。不是键)并获得不同的值?



任何解决方案都将不胜感激.....

解决方案

问题不是很清楚。我不理解你想用什么标准来比较哈希值(它是内部数组 - 比较长度或数组的元素??)。另外,让我们知道你到目前为止尝试了什么。

但是,首先,如果你想获得哈希的值,你可以使用''values''关键字。

例如

展开 | 选择 | Wrap | 行号


感谢您的回复。

i想要比较的值%h1的值为%h2,最终结果为
(%h1的值,%h1而不是%h2)

结果是:


[''ghi'',''jkl'']

[''hop''' UIO]


(因为,这些都不是在%H 2)。

我想上面的输出。我怎么能这样做?????



感谢您的回复。

i想要比较这些值%h1的值为%h2,最终结果为
(%h1的值,%h1,而不是%h2)

结果是:


[''ghi'',''jkl'']

[''hop''''uio'']


(因为,这些不在%h2中)。

我想要上面的输出。我怎样才能做到这一点?????



您可以使用Data :: Compare模块来比较perl中的数据结构。

展开 | 选择 | Wrap | 行号< /跨度>

Hi
I have hashes with arrays to its keys like,
%h1 = (''a''=>[''abc'',''def''],
''b''=>[''ghi'',''jkl''],
''c''=>[''hop'',''uio'']
);

%h2 = (''a''=>[''abc'',''def''],
''b''=>[''wert'',''wer'']);
then, how can i compare the 2 hashes(based on values. not keys) and get distinct values ?


Any solution will be appreciated.....

解决方案

The question is not very clear. I am not understanding with what criteria you want to compare the values of hashes(which are inturn arrays-compare lengths or elements of array??) . Also, let us know what have you tried so far.
However, to begin with if you are trying to get values of the hash, you may use ''values'' keyword.
e.g.

Expand|Select|Wrap|Line Numbers


Thanks for responding.
i want to compare the values of %h1 with values of %h2 and the final result will be

( the values of %h1, which are in %h1 and not in %h2)
Result is :

[''ghi'' , ''jkl'' ]
[ ''hop'' '' uio'']

(since, these are not in %h2).
I want the above output. How can i do this?????


Thanks for responding.
i want to compare the values of %h1 with values of %h2 and the final result will be

( the values of %h1, which are in %h1 and not in %h2)
Result is :

[''ghi'' , ''jkl'' ]
[ ''hop'' '' uio'']

(since, these are not in %h2).
I want the above output. How can i do this?????

You can make use of Data::Compare module to compare data structures in perl.

Expand|Select|Wrap|Line Numbers


这篇关于如何通过值(而非键)比较2个数组的哈希值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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