Perl   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在Perl中比较两个哈希值,而不使用Data :: Compare?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在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.

大佬总结

以上是大佬教程为你收集整理的如何在Perl中比较两个哈希值,而不使用Data :: Compare?全部内容,希望文章能够帮你解决如何在Perl中比较两个哈希值,而不使用Data :: Compare?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。