加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在Perl中比较两个哈希值,而不使用Data :: Compare?

发布时间:2020-12-15 22:02:06 所属栏目:大数据 来源:网络整理
导读:如何在Perl中比较两个哈希值,而不使用Data :: Compare? 解决方法 最好的方法根据你的目的不同. Sinan提到的FAQ项目是一个很好的资源: How do I test whether two arrays or hashes are equal?.在开发和调试(当然编写单元测试)时,我发现 Test::More 在比??
如何在Perl中比较两个哈希值,而不使用Data :: Compare?

解决方法

最好的方法根据你的目的不同. Sinan提到的FAQ项目是一个很好的资源: How do I test whether two arrays or hashes are equal?.在开发和调试(当然编写单元测试)时,我发现 Test::More在比??较数组,散列和复杂数据结构时是有用的.一个简单的例子:
use strict;
use warnings;

my %some_data = (
    a => [1,2,'x'],b => { foo => 'bar',biz => 'buz' },j => '867-5309',);

my %other_data = (
    a => [1,j => '867-5309x',);

use Test::More tests => 1;
is_deeply(%other_data,%some_data,'data structures should be the same');

输出:

1..1
not ok 1 - data structures should be the same
#   Failed test 'data structures should be the same'
#   at _x.pl line 19.
#     Structures begin differing at:
#          $got->{j} = '867-5309x'
#     $expected->{j} = '867-5309'
# Looks like you failed 1 test of 1.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读